SkyWalker
SkyWalker

Reputation: 14309

How to escape single quotes or otherwise reach the final result?

I have the following input:

x = ['a', 'b', 'c']

I'd like to get the following output:

some blah blah ['a', 'b', 'c'] and blah.

I try the following but can't find a way to escape the single quotes:

f"some blah blah ['{', '.join(x)}'] and blah."

Upvotes: 1

Views: 33

Answers (1)

Nk03
Nk03

Reputation: 14949

You can use

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

Upvotes: 1

Related Questions