码迷,mamicode.com
首页 > 编程语言 > 详细

python-%操作符

时间:2017-12-12 23:49:01      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:size   selected   -o   height   div   占位符   body   end   operator   

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 








python-%操作符

标签:size   selected   -o   height   div   占位符   body   end   operator   

原文地址:http://www.cnblogs.com/Bella2017/p/8030007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!