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 String Formatting

What am i doing wrong?

I simply don't understand what I'm doing wrong here? whenever i submit this code i get a "Bummer! Be sure to use the '{}' placeholder and the '.format()' method."

thanks a lot.

strings.py
name="Oliver"
subject="Treehouse loves {}"

subject.format(name)
josiah dubose
josiah dubose
2,525 Points

is it asking you to print out the formatted string or store in a variable ?

  1. make the email subject one more time, but this time use the .format() method for strings. go ahead and make your name variable again.
  2. use .format() on the string "Treehouse loves {}" to put your name into the placeholder. assign this to the variable subject again.

2 Answers

josiah dubose
josiah dubose
2,525 Points

The method call goes on the end of the string like this : subject = "Treehouse loves {}.".format(name)

hmm. That gives me the exact same error?

I'm not sure if you have to do this, but I usually put the .format on the same line that I create the variable in.

This makes the code cleaner:

name = "Yourname"

subject = "Treehouse loves {}".format(name)

I know this is basically the same answer as Josiah, but I tried this and it works.