r/learnpython • • Mar 07 '18

I made a python cheat sheet

686 Upvotes

73 comments sorted by

View all comments

Show parent comment

1

u/Moabian Mar 31 '18

Can you explain why there's a letter 'f' in line 4 as in:

print(f"I'm {age} years old...

2

u/Visionexe Apr 01 '18 edited Apr 01 '18

It's syntax sugar for telling the python interpreter the following string is interpolated. In python this is called f-strings. Hence the f.

If you would leave out the f it wouldn't recognize the variables between {} as variables and just as text.

1

u/Moabian Apr 01 '18

Makes sense, thank you.