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 trialcharvakthatha
450 PointsString formatting, why isn't this working
I think my code is correct, but I don't why it isn't working
name = "Sud"
subject = "Treehouse Loves {}".format("Sud")
I've even tried to do this.
.format(name)
3 Answers
tobiaskrause
9,160 PointsThere you go
name = "Sud"
subject = ("Treehouse loves {0}").format(name)
With the Formatter the {0} becomses the name variable (parameter). 0 means it gets the first varaible
Another example
name1 = "Sud"
name2 = "Ben"
name3 = "Chris"
subject = ("Treehouse loves {0}, {1} and {2}").format(name1, name2, name3)
this makes the string to "Treehouse loves Sud, Ben and Chris
more information: https://docs.python.org/2/library/string.html#format-examples
charvakthatha
450 PointsOkay, thanks
charvakthatha
450 PointsOkay, thanks