Steven D'Aprano <[email protected]> added the comment:
Just change the f string quotes.
Python strings, whether f-strings or not, can be delimited by '' or "" or
triple quotes. So this works:
>>> f"But, {'this quote is right.'}"
'But, this quote is right.'
Remember that the part of the f-string is evaluated as code, converted to a
string, and interpolated into the rest of the f-string body. This is why the
quotes disappear.
If you need both kinds of quotes, use triple-quotes as the delimiter:
>>> f"""Both {'single and "double" quotes'.title()}"""
'Both Single And "Double" Quotes'
I assume you want to pass the '' string to a function or something, and this
example is just a simplified version. Because if there is no function call
needed, you should just use a regular string, there's no need for an f-string:
"But, 'this quote is right.'"
----------
nosy: +steven.daprano
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41240>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com