首页 > 其他 > 详细

字符串格式化

时间:2020-01-27 10:14:46      阅读:108      评论:0      收藏:0      [点我收藏+]

1、打印浮点数%f

tp1="percent %.2f"%99.976234444444444444
print(tp1)

tp1="percent %.3f"%99.976234444444444444
print(tp1)

>>>

percent 99.98
percent 99.976

2、打印字符串%s,

      #字符串可接收数字,可接收浮点数

msg1 = my name is %s, my hobby is %s   %(fu,pingpang)
msg2 = his name is %s   %zheng
print(msg1)
print(msg2)

>>>

my name is fu, my hobby is pingpang
his name is zheng

3、打印数字型%d

msg1 = my name is %s, my age is %d   %(fu,20)
print(msg1)

>>>my name is fu, my age is 20

4打印百分号%%

tpl= percent %.2f %%     % 99.976234444
print(tpl)

>>>percent 99.98 %

字符串格式化

原文:https://www.cnblogs.com/forhowcar/p/12235463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!