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 trial

Python Python Basics (Retired) Ins & Outs Ins & Outs

Rogier Leegwater
Rogier Leegwater
5,589 Points

create a new variable named email_greeting that uses str.format to combine the treehouse variable, the word "loves", and

python basics

2 Answers

Or you can do it like this:

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

That's probably the better solution, to be honest.

Thanks steve.

Hi Rogier,

For this, you want to interpolate the two varialbes you have created into one larger string using the str.format() function.

Like this:

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

At each marker point, {}, the variables listed at the end, between commas, will be inserted in turn. So, the value held inside the treehouse variable will be inserted at the first {}, then the value held inside the name variable will be inserted at the second. The output will be Treehouse loves Steve, where variable treehouse contains "Treehouse" and the variable name contains "Steve".

I hope that helps.

Steve.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,427 Points

I would not have downvoted this answer. Though not the Pythonic idiom most expect, it does solve the problem and it illustrates that you can access and use methods defined in a class. Please consider removing the downvote.

Ha! I hadn't realised I got downvoted for that ... hey ho!