Python格式化输出%s和%d
本文介绍了Python格式化输出%s和%d的实例案例。分享给大家供大家参考,具体如下:
python print格式化输出
1. 打印字符串
print ("His name is %s"%("Aviad"))
效果:
2.打印整数
print ("He is %d years old"%(25))
效果:
3.打印浮点数
print ("His height is %f m"%(1.83))
效果:
4.打印浮点数(指定保留小数点位数)
print("His height is %.2f m"%(1.83))
效果:
5.指定占位符宽度
print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))
效果:
6.指定占位符宽度(左对齐)
print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))
效果:
7.指定占位符(只能用0当占位符?)
print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))
效果:
8.科学计数法
format(0.0015,'.2e')
效果:
相关推荐
FlySky 2020-11-02
逍遥友 2020-10-26
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02
葫芦小金刚 2020-07-28
StevenSun空间 2020-07-26