Python Python Basics (2015) Python Data Types Strings

The .format() method

What would be a real world instance of using a string as a template for which the .format method was used to fill in any placeholder curly braces?

1 Answer

Benjamin:

my_string.format(**my_dict) //returns interpolated string, pulling values from my_dict
def string_factory(dicts, string):
  i = 0
  new_list = []
  for dict in dicts:
    new_list.append(string.format(**dicts[i]))
    i += 1
  return new_list
print('{first} {last} <{email}>'.format(**match.groupdict()))
for key, value in menu.items():
    print('{}) {}'.format(key, value.__doc__))