+ 9
f-string backslash needs escape - sometimes
OK Pythonistas, why does the backslash in line 5 need an escape backslash when the backslashes in lines 4, 6 and 7 don't? It's not a Code Playground quirk as the code works the same in Pydroid3. I know you can't put a backslash inside an f-string {} expression - hence the use of chr() - but this is weird 🤔 https://code.sololearn.com/c6sWEp4221jX/?ref=app
7 Réponses
+ 9
I think the answer is that otherwise the backslash would escape the quotation mark and the f-string would carry on into the next line.
+ 2
The Learner Here is some info on f-strings and some codes using them https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-f-strings/
https://code.sololearn.com/cDWO70CXBHCG/?ref=app
https://code.sololearn.com/cL47YsleH5I2/?ref=app
https://code.sololearn.com/c0AEk03cLwyF/?ref=app
+ 1
David Ashton, Thank you so much
I will check them 👍😁
0
What does f-string do in Pyrhon?
0
F-string what did string ever do to you. Ba-dum-bum.
0
F string basically is a way to include variables or some expression inside an output string
s="house"
print(f"My {s} was burnt by them")
Output: My house were burnt by them
this is basically a faster and more intuitive way of implementing the same logic achieved by using + to concat during output or using the %d %s and such in some other languages
- 2
Can someone please and this
>>>' '