关键字参数
>>> "{a} am {b}".format(a = "i", b = "system")
'i am system'
>>>
位置参数
>>> '{0} am {1}'.format('i', 'system')
'i am system'
>>>
同时存在时,需要将位置参数放于关键字之前
>>> "{0} am {a}".format("i", a = "system")
'i am system'
>>>
>#如果位置参数放在关键字参数后面,则报错
>>> "{a} am {0}".format(a = "i", "system")
SyntaxError: non-keyword arg after keyword arg
>>>
06格式化字符串
最新推荐文章于 2023-04-19 23:27:21 发布
1146

被折叠的 条评论
为什么被折叠?



