f-strings
An f-string is a string with an f in front that lets you put values inside curly braces {}.
Used in 129 lessons of the course, from 00.01.
An f-string is a string that starts with the letter f before the quote: f"Hello {name}".
Inside the braces {} you can write any Python expression. Python evaluates it, turns the result into text and places it right there.
It is written this way because the text and the values stay together, in the order you read them. You don't have to glue pieces with + or convert with str() by hand.
The braces can hold names, calculations or calls, like {len(items)}. Without the f, the braces print as they are.
In the course you see it in almost every lesson to show results, for example print(f"Glossary loaded: {len(GLOSSARY)} terms."). There len(GLOSSARY) is computed and its number goes into the sentence.
Reach for it when: you want to mix text with values, for example to print a result or build a message.
Examples
Common mistake
name = "Ada"
print("Hello, {name}!")Why: Without the f in front, Python treats the text as a normal string and leaves the braces alone.
How to write it: Put the f before the quote: f"Hello, {name}!".
