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

Steven Olick
Steven Olick
1,561 Points

problem with this?

Hello, I understand that this is the code the site is looking for in terms of the challenge answer:

name = "Steve"

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

However, my original code looked like this:

name = "Steve"

subject = "Treehouse loves {}"

subject.format(name)

This was wrong and I'm having trouble seeing why I can't create the variables and then use them in this manner. I feel like I'm missing a basic concept if I continue too far without knowing why this is incorrect. Can someone help explain? Thanks!

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Steven;

They both are indeed fundamentally the same. The challenge checking engine tends to be a bit picky however and you outsmarted it with your answer. :-)

Post back with any further questions.

Happy coding,
Ken

Steven Olick
Steven Olick
1,561 Points

Thanks for your fast response! I'm relieved.

Hello,

That method works.

Treehouse probably uses some regular expression to scan your string and looks for a specific pattern in this way, but there's nothing wrong with using format method that way.