标签: python arrays string list format
如何以一种方式使用string.format():
string.format()
line = 'first {0}, second {1}' print(line.format([1,2]))
会打印first 1 second 2。
first 1 second 2
答案 0 :(得分:4)
你可以unpack the list:
>>> line = 'first {0}, second {1}' >>> l = [1, 2] >>> print(line.format(*l)) first 1, second 2