python-%操作符

1.打印字符串

print("His name is %s"%("Aviad"))
His name is Aviad

2.打印整数
print("He is %d years old"%(25))
He is 25 years old
 
3.打印浮点数
print("His height is %f m"%(1.83))
His height is 1.830000 m
 
4.指定小数点位数,打印浮点数
print("His height is %.2f m"%(1.83))
His height is 1.83 m

5.指定占位符宽度(左对齐)
print("Name:%-10s Age:%-5d Height:%-5.2f"%("Aviad",25,1.83))
Name:Aviad      Age:25    Height:1.83 








posted @ 2017-12-12 22:11  爱学英语的程序媛  阅读(544)  评论(0编辑  收藏  举报