MoonLab - TIL

This is where i store my today-i-learned

You may also wannna visit my blog

Home

Python String Format

f-strings (Python 3.6+)

name = "Alice"
age = 30
formatted_string = f"My name is {name} and I am {age} years old."

str.format()

name = "Bob"
age = 25
formatted_string = "My name is {} and I am {} years old.".format(name, age)

Percent % formatting

name = "Charlie"
age = 22
formatted_string = "My name is %s and I am %d years old." % (name, age)