Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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__))