Author steven.daprano
Recipients Nghia Minh, eric.smith, steven.daprano
Date 2020-07-08.10:47:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594205279.1.0.342310151747.issue41240@roundup.psfhosted.org>
In-reply-to
Content
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.'"
History
Date User Action Args
2020-07-08 10:47:59steven.dapranosetrecipients: + steven.daprano, eric.smith, Nghia Minh
2020-07-08 10:47:59steven.dapranosetmessageid: <1594205279.1.0.342310151747.issue41240@roundup.psfhosted.org>
2020-07-08 10:47:59steven.dapranolinkissue41240 messages
2020-07-08 10:47:59steven.dapranocreate