常用的格式化
- “%s”% :%空格处向%s传值,s表示传值的是字符串类型。可以传多个值,用"%s",% (,)。tpl = “i am %s” % “alex”
- “%d”% :%d表示传整型。tpl =“i am %s age %d” % (“alex”, 18)
- “%.2f”% :%.2f表示传浮点型,并保留小数点后两位。tpl =“percent %.2f” % 99.97623
- “%.2f%%”% :表示传百分号。tpl=“i am %.2f %%” % {“pp”: 123.425556, }
- 键值对传值:
“i am %(name)s age%(age)d” %{“name”:“alex”,“age”:18}
百分号
%[name][flag][width][.precision][typecode]
fermat()
" ",format(),传的值需要一一对应。