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

How do I use format for subject variable

name = "Dmitry Kozloff" subject = "Treehouse loves {}" How to use .format to place name in {}

strings.py
name = "Dmitry Kozloff"
subject = "Treehouse loves {}"
print(subject.format(name))

1 Answer

Buddy, dont waste your time... check if it doesn't work try on your python console. If it(python console) gives error then you are missing some point. Don't completely trust the console/evaluation of treehouse.

What you are doing is:

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

which is perfectly correct and makes sense. But treehouse wants it a little differently.

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

same thing right? but this would pass their test and the previous wont.

I know... it sucks sometimes.

Dylan Davenport
Dylan Davenport
Courses Plus Student 2,645 Points

I've had the same thing happen. The treehouse console wants it EXACTLY their way and their way only haha.