How to put backslash escape sequence into an f-string
source link: https://proinsias.github.io/til/how-to-put-backslash-escape-sequence-into-an-f-string
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Francis T. O'Donovan
Senior Data Science Manager at Hospital IQ – Planet discoverer, researcher, developer, geek.
How to put backslash escape sequence into an f-string
less than 1 minute read
If you want to write something like:
"{}MESSAGE{}".format("\t"*15, "\t"*15)
but using f-strings, you hit the issue that you cannot have a backslash inside an f-string expression.
Instead you should assign the tab character to a variable and then use that:
tab = '\t' * 15
f"{tab}MESSAGE{tab}"
Via SO.
Categories: til
Updated: October 23, 2022
You May Also Enjoy
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK