f-Strings: Fill in the Blanks ๐งฉ
Want to mix variables into a sentence? Use an f-string: put an f
right before the quotes, then drop variables into {curly braces}:
name = "Zoe"
age = 12
print(f"{name} is {age} years old") # โ Zoe is 12 years old
Python fills in the blanks for you. It even does math inside the braces:
print(f"Next year I'll be {age + 1}!")
Your mission
- Make a variable
animal(any animal) andcount(any number) - Use one f-string to print a sentence like:
I saw 7 wolves at the park!โ with your animal and number filled in from the variables
Your code
Press โถ Run to see what your code does!