python_introduction/examples/string_format.py

19 lines
324 B
Python

# Basic placeholders
ingredient = "sugar"
quantity = "500g"
ingredient_string = "- {}: {}".format(ingredient, quantity)
print(ingredient_string)
# Named placeholders
fname = "John"
lname = "Doe"
bond_string = "My name is {lastname}, {firstname} {lastname}".format(firstname=fname, lastname=lname)
print(bond_string)