标签:数字 pre name code obb span 接收 color 字符串
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 %
标签:数字 pre name code obb span 接收 color 字符串
原文地址:https://www.cnblogs.com/forhowcar/p/12235463.html