name = "Maya"
message = f"Hello, {name}!"Line-by-line explanation
- The first line stores a name.
- The
fmarks the second string as an f-string. {name}is replaced by the value inname.messagestoresHello, Maya!.
Tiny Practice
Create the message “You have 3 lives” using the variable.
Starter template
lives = 3
message = CHANGE_ME
print(message)Line-by-line explanation
- The first line stores the number.
- The second line must create an f-string.
- The last line displays it.
Hint
- Start the string with
f. - Put
livesin curly braces. - Keep the other words inside quotes.
Show Solution
lives = 3
message = f"You have {lives} lives"
print(message)Line-by-line explanation
- The first line stores 3.
- The f-string inserts that value.
- The output is
You have 3 lives.