Python format() built-in function

From the Python 3 documentation

Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument. [...].

Examples

name = 'Micheal'
company = 'Dunder Mifflin'

print("My name is {0} and I work for {1}.".format(name, company))

# Formatting string (faster and easier)
print(f"My name is {name} and I work for {company}.")

Subscribe to pythoncheatsheet.org

Join 10.100+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.