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

Jabari Bellamy
Jabari Bellamy
9,513 Points

How do I complete the second challenge task for learning how to use the .format method and the {} inside the string?

I have tried different methods and I thought this was a easy challenge task, but there's something that I am doing wrong. I have used both the .format method and the {} inside my strings and I'm still getting this bummer message and I don't understand why. Any help is highly appreciated.

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

2 Answers

andren
andren
28,558 Points

The problem is that the challenge does not ask you to print out a formatted string, it expliclity asks you to format the string that you store into the subject variable. You can do that in a single line by calling the format method directly on the string like this:

name = "Jabari"
subject = "Treehouse loves {}".format(name) # This formats the string and then stores it into "subject"
Jabari Bellamy
Jabari Bellamy
9,513 Points

Thank you so much Andren. I really appreciate your help. I knew this wasn't an easy task. For some reason, i just didn't understand the task fully and you are correct, the challenge didn't say to print out a formatted string and for some reason I have printed the formatted string the whole time. Thank you so much for simplifying how to complete the challenge task for me. Much is very appreciated.