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 trialAntonie Huang
985 PointsHow to use format command
Task 3 I need to try str.format, but I don't really know how to do it?
1 Answer
Vittorio Somaschini
33,371 PointsHello Antonie.
email_greeting has to be set to a string, right?
It has to, but not only, the string has to contain placeholders, so that we can use the format method to fill in the placeholders with the right values (treehouse and name).
A placeholder is create doing this: {}
So:
email_greeting = '{} loves {}'
On this string you will need to apply the format method. Does it make sense? Please paste your code if you need more help.
Vitto
Antonie Huang
985 PointsAntonie Huang
985 Pointsname = 'Antonie'
treehouse = 'Tree' + 'house'
email_greeting = '{treehouse} loves {name}'
I've done what you told me, but it still doesn't work
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsIn the format statement, the {} fields are filled from argument supplied:
email_greeting = '{} loves {}'.format(treehouse, name)