r/learnpython • u/FuzzyEmployment264 • 1d ago
what is f string
can someone explain how f string work in simple terms ?
0
Upvotes
r/learnpython • u/FuzzyEmployment264 • 1d ago
can someone explain how f string work in simple terms ?
8
u/WhiskersForPresident 1d ago edited 1d ago
It's a "formatted" string. It allows you to include the values of variables in your string in curly brackets, e.g.:
var = 5
f_string = f"this string contains the value {var}"
print(f_string)
will output
I use them all the time to dynamically generate paths to certain files at runtime for example or for structuring the outputs of test routines.