本文共 1358 字,大约阅读时间需要 4 分钟。
%(name)[width].[precision]typecode
flags 可选,可供选择的值有:
typecode 必选
注:Python中百分号格式化是不存在自动将整数转换成二进制表示的方式
msg='i am %s hobby is alex' % 'lhf'print(msg)---i am lhf hobby is alexmsg='i am %s my hobby is %s' % ('lhf','alex')print(msg)---i am lhf my hobby is alex
msg='i am %s my hobby is %d' % ('lhf',1)print(msg)---i am lhf my hobby is 1
tp1 = "percent %.2f" % 99.9723423423print(tp1)---percent 99.97# 打印出百分号,tp1 = "percent %.2f %%" % 99.9723423423print(tp1)---percent 99.97 %
tp1 = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}print(tp1)---i am alex age 18
print('root','x','0','0',sep=':')---root:x:0:0
转载地址:http://zycia.baihongyu.com/