diff --git a/examples/string_format.py b/examples/string_format.py index 554a100..2ec6f87 100644 --- a/examples/string_format.py +++ b/examples/string_format.py @@ -1,4 +1,4 @@ -# Basic placeholders +# Basic placeholders usage ingredient = "sugar" quantity = "500g" @@ -8,7 +8,24 @@ ingredient_string = "- {}: {}".format(ingredient, quantity) print(ingredient_string) -# Named placeholders + + +# Indexed placeholders usage +# +# Placeholders are identified by index number, 0 being the first parameter passed + + +name = "John" +age = 30 + +greetings = "My name is {0}, i'm {1}.".format(name, age) + + + + +# Named placeholders usage +# +# Placeholders are identified by name, order doesn't matter fname = "John" lname = "Doe" @@ -16,3 +33,8 @@ lname = "Doe" bond_string = "My name is {lastname}, {firstname} {lastname}".format(firstname=fname, lastname=lname) print(bond_string) + + + + +