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

string formating

I am havin difficulty with this string. I may be over thinking this again. Please help!

name = "justine" subject = "Treehouse loves " + name del subject subject = "Treehouse loves " + "{}" print(subject.format(name))

strings.py

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I feel like you might need to review the .format method. It seems like it's all getting a bit jumbled up at this point. But here is what they're looking for:

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

So we make our name variable again and assign a string to it (in this case "justine"). Then we make another variable named subject. Now here comes the interesting part. When we put those curly braces inside the string we're using them as placeholders. Then after the quotes we call the format method and pass it a variable. This is our way of telling Python to put the value of that variable in that spot.

So if we had this:

x = 9
valueX = "The value of x is:  {}".format(x)

... our valueX would have a string stored in it that looks like this "The value of x is: 9". Hope this helps! :sparkles:

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