【1.20】百分号使用【主要】
1、百分号 用来直接连接要替换的数据
%s 可以用来替换所有要输入的数字,字符串、列表、字典
但是不能是元组
tpl = "i am %s" % "alex"2、%d 用来接收输入的数字
tpl = "i am %s age %d" % ("alex", 18)3、格式:%(变量)数据类型,定义输入的变量 以及其类型,用于字典输入
%(name)s
%(age)d
tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}4、%.2f 用于浮点数的输入,并限制小数的位数,进行四舍五入
tpl = "percent %.2f" % 99.976235、同 3 和 4
tpl = "i am %(pp).2f" % {"pp": 123.425556, }6、这个是用于输出 百分号 %
tpl = "i am %.2f %%" % {"pp": 123.425556, }
浙公网安备 33010602011771号