如何转义单引号或以其他方式获得最终结果



我有以下输入:

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."

相关内容

最新更新