python_introduction/examples/string_format.py

19 lines
324 B
Python
Raw Normal View History

2021-10-28 09:16:46 +02:00
# Basic placeholders
ingredient = "sugar"
quantity = "500g"
ingredient_string = "- {}: {}".format(ingredient, quantity)
print(ingredient_string)
# Named placeholders
2021-10-27 20:11:34 +02:00
fname = "John"
lname = "Doe"
bond_string = "My name is {lastname}, {firstname} {lastname}".format(firstname=fname, lastname=lname)
print(bond_string)