python f strings
f-strings allow you to place values and variables inside a string,
which is cleaner than using "{}".format(var).
f"I'm an f-string with a variable: {variable} :D"
Full example:
animal = "Goat"
street_number = 10
f"There's a {animal} living in unit {street_number} down the road?"
since f-strings are evaluated at runtime, you can also do calculations or call functions within them:
city = "Melbourne"
f"My favourite city is {city.title()}"
For multi-line, be sure to add "f" infront of each line:
city = "Melbourne"
food = "Pancakes"
my_story = (
f"I'm in {city}. "
f"I eat {food}. "
)
SNAPPED!

SNAPPED!
Comments
Post a Comment