4 ms·
Your first example works fine as an f-string without resorting to escaping, etc: >>> def some_function(): ... return ['a','b','c'] ... >>> li
by Mister_Snuggles 6y ago
Your first example works fine as an f-string without resorting to escaping, etc:
>>> def some_function():
... return ['a','b','c']
...
>>> list_of_items = ['one','two','three']
>>> s = f"The {some_function()[1]} is a problem, please look at: {' '.join([item for item in list_of_items])}"
>>> s
'The b is a problem, please look at: one two three'
>>>
I'll admit that it's somewhat ugly, but there's no escaping needed.
- BerislavLopac 6y agoIn this particular example it gets even simpler: s = f"The {some_function()[1]} is a problem, please look at: {' '.join(list_of_items)}"
- pydry 6y agoYep and then as soon as you add quotation marks it breaks down: s = f"The {some_function()["WHOOPS!!!"]} is a problem, please look at: {' '.join([item for item in functino_call("whoops again")])}" This indirectly proves the point I think.