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

Joshua Sklodowska
Joshua Sklodowska
1,146 Points

OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the va

I entered

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

What variable do that want me to assign to the subject? I think I'm misunderstanding the question. I thought using the .format() on the string "Treehouse loves {}" was the variable to which I assign subject with the equals sign. Why wouldn't that be the case? (Evidently it's not.)

strings.py
name='josh'
"Treehouses loves{}".format(name) 

3 Answers

name = 'Josh'
subject = 'Treehouse loves {}'.format(name)
name = 'Darrian'
subject = 'Treehouse loves {}'.format(name)

 # here the curly braces are a blank place holder that puts the string "Darrian" from the variable name into subject.

you can get more help from the python shell by typing in 'help(format)' no quotes of course

so what's happening here is that you have the string in the variable 'subject' and the curly braces are acting as a place holder for the method '.format' does that help?

Joshua Sklodowska
Joshua Sklodowska
1,146 Points

@darrian thomas I understand. I just don't get how that's different from what I entered. I will try again.

Brian Pitts
PLUS
Brian Pitts
Courses Plus Student 3,826 Points

According to the directions in the python strings section, "...use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject again."


name = "Brian" subject = "Treehouse loves {}"

subject = subject.format(name)

Does not complete the challenge. Anyone know why? Works in the shell just fine, but not in the assignment challenge.