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

john herron
john herron
2,485 Points

Im on the .format() code challenge on python and Im completely lost on what to do

name = "john" subject = "treehouse loves {}" .format("john")

can anyone point out what I'm doing wrong?

name = "john"
subject = "treehouse loves {}"

2 Answers

Hi John so for this challenge, the marker is expecting a variable name to be passed to the format method. The way you have written the code, it makes the variable 'name' redundant. When i say redundant i mean you assigned your name to the variable 'name' but then passed a static string to the format method.

so if you pass the variable name to the format method the code would pass.

name = "john"
subject = "treehouse loves {}"
Jason Anders
Jason Anders
Treehouse Moderator 145,857 Points

Hey John,

You're on the right track. There are just a couple of things.

  • When you use the format() method, it has to be used directly on the string being formatted. So, you can't use a second declaration of the variable.

  • You will want to pass in the variable name into the format method and not a hard coded string

  • Finally, and this one is just because the code checker for the challenges are very picky and specific, "Treehouse loves..." needs a capital "T".

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

Hope this helps. Keep Coding! :)