我有以下输入:
x = ['a', 'b', 'c']
我想得到以下输出:
some blah blah ['a', 'b', 'c'] and blah.
我尝试了以下操作,但找不到逃避单引号的方法:
f"some blah blah ['{', '.join(x)}'] and blah."
您可以使用
x = ['a', 'b', 'c']
print(f"some blah blah {x} and blah.") # will print "some blah blah ['a', 'b', 'c'] and blah."
print(f"some blah blah [{', '.join(x)}] and blah.") # will print "some blah blah [a, b, c] and blah."