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 trialoliverchou
20,886 Pointsabout the format method
when I write: .format(name) does the format method put in the "name" or the variable?
2 Answers
Russell Sawyer
Front End Web Development Techdegree Student 15,705 PointsThe .format() puts whatever you have in the parentheses inside the place holder in the string represented by the {}. For the challenge you put the variable in the parentheses and the output would be "Treehouse loves Kevin".
name = 'Kevin'
subject = "Treehouse loves {}".format(name)
If you put a string in the parentheses instead of a variable then the result would be "Treehouse loves Russell"
name = 'Kevin'
subject = "Treehouse loves {}".format('Russell')
Also, you can pass multiple values with multiple place holders. "Treehouse loves Kevin and Russell"
name = 'Kevin'
subject = "Treehouse loves {} and {}".format(name, 'Russell')
oliverchou
20,886 Pointsthanks a lot~ :)
David Dzsotjan
5,929 PointsDavid Dzsotjan
5,929 PointsIn this form, it will put the value of the <name> variable in the placeholder, as in
To put the word 'name', you gotta type
print('{}'.format('name')) # will output name
Hope this helps :)