【发布时间】:2020-04-20 15:31:33
【问题描述】:
我正在尝试格式化下面的代码,但它失败了,因为大括号已经到位,所以格式化功能不起作用。
def in_list(line):
input = '{"word1":["one"], "word_list":{}, "bool":true}'.format(line)
print(input)
msg = ["hello", "how", "are", "you"]
in_list(msg)
Expected Output:
'{"word1":["one"], "word_list":["hello","how","are","you"], "bool":true}'
有没有办法将列表传递到句子中。请告诉我,谢谢。
【问题讨论】:
标签: python python-3.x string list formatting