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 trialChris Phillips
220 PointsI'm formatting strings like so: subject = "Treehouse loves {}" print(subject.format(name)) it works in the console
I'm formatting strings like so: subject = "Treehouse loves {}" print(subject.format(name)) works in the console but not in the lesson...
name = "Chris"
subject = "Treehouse loves {}"
print(subject.format(name))
2 Answers
Stéphane Diez
19,350 PointsWhen you use {} in a string, you need to format that with the format() function.
name = "Chris"
subject = "Treehouse loves {}".format(name)
print(subject)
Chris Phillips
220 Pointsyes, that's how I finally solved it... but it works both ways...
subject="blah blah blah {}" subject.format(name)
is the same as
subject="blah blah blah {}".format(name)
isn't it?
Stéphane Diez
19,350 PointsYes it's the same, but it's better to use .format() after the string.