字符串格式化 %s format
作者:互联网
1 # 字符串格式化 2 #%s 3 4 5 # s = 'i am a %s ii iii jjj' %'kkkkkk' 6 # print(s) 7 8 # s = 'i am a ii iii jjj' + 'kkkkkk' 9 # print(s) 10 11 # n = 'i am a %s ii iii jjj %s' % ('pp','pppo') 12 # print(n) 13 14 # s = 'i am a %s ii iii jjj %s' % ('pp','89') 15 # print(s) 16 # 17 # %d只能接收数字 18 19 20 # 打印浮点数 21 # i= "percent %.7f" % 12.13213546546 22 # print(i) 23 24 25 26 # i= "percent %.3s" % 'abcdefg' 截取字符串 27 # print(i) 28 # percent abc 29 30 #打印百分比 31 # i = "percent %.3f %%" % 12.123456789 32 # print(i) 33 34 #用字典的k 值进行拼接 35 36 #print('rooot','a','b','c',sep=':') # 输出的值为 rooot:a:b:c 37 38 39 40 #format字符串格式化 41 42 # i = 'i am {}, {}, {}, opopop'.format('hahah','heihiehie','啦啦啦啦啦啦') 需要一一对应 43 # print(i) 44 45 #可按指定顺序进行连接 46 #i = 'i am {2}, {1}, {0}, opopop'.format('hahah', 'heihiehie', '啦啦啦啦啦啦') 47 #print(i) 48 49 #字典形式格式化 50 # i = 'i am {name},age{age},really{name}'.format(**{'name' :'77','age':'pppppppppp'}) 51 # print(i)
标签:格式化,format,percent,am,print,jjj,字符串,iii 来源: https://www.cnblogs.com/luoluokang/p/12436239.html