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!

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 (Retired) Ins & Outs Ins & Outs

Antonie Huang
Antonie Huang
985 Points

How 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
Vittorio Somaschini
33,371 Points

Hello 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: {}


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.


Antonie Huang
Antonie Huang
985 Points

name = 'Antonie'

treehouse = 'Tree' + 'house'

email_greeting = '{treehouse} loves {name}'

I've done what you told me, but it still doesn't work

Chris Freeman
Chris Freeman
Treehouse Moderator 68,404 Points

In the format statement, the {} fields are filled from argument supplied:

email_greeting = '{} loves {}'.format(treehouse, name)