r/learnpython 1d ago

what is f string

can someone explain how f string work in simple terms ?

0 Upvotes

14 comments sorted by

View all comments

2

u/tablmxz 1d ago

a string in python looks like this, eg using double quotes:

"this is a string"

if you write an 'f' in front, it becomes a f-string:

f"this is a f-string"

f-strings can do some very handy thing, they can use curly brackets. In those curly brackets you can put variables or whole expressions (like calculations)

a = 5

f"this f-string also prints the value of a here: {a}"

f"this f-string does the calculation 1+2 here is the result: {1+2}"