不幸的是,* 或 ** 运算符的变体似乎不起作用:
lstData = [1,2,3,4]
str = 'The %s are %d, %d, %d, and %d' % ('numbers', *lstData)
有什么简单的方法吗?
最佳答案
使用 format :
str = 'The {} are {}, {}, {}, and {}'.format('numbers', *lstData)
有关可能的格式( float 、小数点、转换......)的更多详细信息,请参阅文档。
https://stackoverflow.com/questions/7978144/