Python占位符 %d %s %f %r的使用


1.%d代表数字占位符,代表int整型,只能传递十进制整数


1.1
Python占位符 %d %s %f %r的使用_第1张图片
1.2
Python占位符 %d %s %f %r的使用_第2张图片
1.3
Python占位符 %d %s %f %r的使用_第3张图片


2.%s代表字符串占位符 , 代表string 字符串


string = “hello word”
print(“输出=%s”%string)
#打印字符串"hello word"
2.1
Python占位符 %d %s %f %r的使用_第4张图片
2.2
Python占位符 %d %s %f %r的使用_第5张图片
2.3
Python占位符 %d %s %f %r的使用_第6张图片


3.%f 代表浮点,默认保留6位小数位,而第7位根据四舍五入取值


3.1
Python占位符 %d %s %f %r的使用_第7张图片
3.2
Python占位符 %d %s %f %r的使用_第8张图片
3.3
Python占位符 %d %s %f %r的使用_第9张图片


4.%r 万能统配符 (可以将后面给的参数原样打印出来,带有类型信息)


Python占位符 %d %s %f %r的使用_第10张图片

你可能感兴趣的:(python)