大家好,又见面了,我是你们的朋友全栈君。
一、例子:
"_".join(["1","2","3","4"]) "_".join(map(lambda x:str(x),[1,2,3,4])) "{0}-{1}".format(3.4,34) "{}-{}-{}".format(3,4,5) "{name}-{age}".format(**{'name':'song','age':34}) "{name}-{age}".format(name='song',age=34) "the list first is: {obj[0]}".format(obj=[1,2,3,4]) "the list first is: {0[0]},{0[1]}".format([1,2,3,4]) "{:>8}".format('abc') "{0:<8}".format('abc') "{0:_<8}".format('abc') "{0:0>8}".format('3.14') "{0:.2f}".format(123.123456) "{0:b}".format(1023) "{0:d}".format(0b1111111111) "{0:x}".format(1023) "{0:,}".format(102345.6789)
二、结果:
>>> "_".join(["1","2","3","4"]) '1_2_3_4' >>> "_".join(map(lambda x:str(x),[1,2,3,4])) '1_2_3_4' >>> "{0}-{1}".format(3.4,34) '3.4-34' >>> "{}-{}-{}".format(3,4,5) '3-4-5' >>> "{name}-{age}".format(**{'name':'song','age':34}) 'song-34' >>> "{name}-{age}".format(name='song',age=34) 'song-34' >>> "the list first is: {obj[0]}".format(obj=[1,2,3,4]) 'the list first is: 1' >>> "the list first is: {0[0]},{0[1]}".format([1,2,3,4]) 'the list first is: 1,2' >>> "{:>8}".format('abc') ' abc' >>> "{0:<8}".format('abc') 'abc ' >>> "{0:_<8}".format('abc') 'abc_____' >>> "{0:0>8}".format('3.14') '00003.14' >>> "{0:.2f}".format(123.123456) '123.12' >>> "{0:b}".format(1023) '1111111111' >>> "{0:d}".format(0b1111111111) '1023' >>> "{0:x}".format(1023) '3ff' >>> "{0:,}".format(102345.6789) '102,345.6789' >>>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/156075.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...