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

Jacob Roff
Jacob Roff
300 Points

what is the correct way to answer this question?

In work spaces the code comes out correctly, so I'm not sure what the deal is. Is the question asking something else?

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

3 Answers

Steven Parker
Steven Parker
229,644 Points

Your final line creates the correct result, but doesn't store it anywhere. You can see it in a REPL, but it is not detected by the challenge when it runs the program since the contents of "subject" don't reflect the final result.

Also, if I remember correctly, this challenge specifically wants you to apply the "format" method directly to the template string on the same line as you make the assignment of the new variable.


So, combining the last 2 lines and applying the format to the template and assigning the result:

subject = "Treehouse loves {}".format(name)
Jacob Roff
Jacob Roff
300 Points

So what would that look like if I applied the format method to that piece of code. I've been back to the video a few times but can't seem to make it work. I'm not sure how I need to write this piece of code.

Steven Parker
Steven Parker
229,644 Points

I expanded my answer with an example.

Jacob Roff
Jacob Roff
300 Points

Thanks appreciate the help