Have you ever played old-school Pokemon and chosen a funny name so that the in-game messages would come out funny?

In Python, we can create strings that contain dynamic values with the f-string syntax.

num_bananas = 10
bananas = f"You have {num_bananas} bananas"
print(bananas)
# You have 10 bananas
  • Add an f to the start of quotes to create an f-string: f"this is easy!"
  • Use curly brackets {} around a variable to interpolate (put) its value into the string.

You can also use an f-string directly inside a print() call, without assigning it to a variable first. It's just a string — don't overthink it!

Source: boot.dev