Python · Stage 2 – Doing Things with Values · Lesson 18 of 50

Formatting Output with f-Strings

Place a variable value inside a readable piece of text.

name = "Maya"
message = f"Hello, {name}!"
Line-by-line explanation
  1. The first line stores a name.
  2. The f marks the second string as an f-string.
  3. {name} is replaced by the value in name.
  4. message stores Hello, Maya!.