Reusing quotes inside an f-string
Before Python 3.12 the first line was a SyntaxError. The second form works on every version.
print shows values on the screen and can be tuned with sep and end. An f-string, written f"...{value}...", builds text by putting values into {} slots, and a format spec such as :.2f or :>8 controls how each value looks.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Set item = "Notebook", price = 45.5, qty = 3, and print Notebook: 3 x 45.50 = 136.50 with an f-string.
Print the number 1234567.891 with commas and one decimal place.
Print the three words red, green, blue on one line separated by | .
Explain it without notes
How do sep and end change what print does?
What is an f-string, and why is it better than joining strings with +?
Explain {value:>8}, {value:.2f} and {value:,}.
What is the difference between str(x) and repr(x)? When would you use repr?
Expected output
abcd
single