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 trialRogier Leegwater
5,589 Pointscreate a new variable named email_greeting that uses str.format to combine the treehouse variable, the word "loves", and
python basics
2 Answers
josephchemaly
2,914 PointsOr you can do it like this:
email_greeting = "{} loves {}".format(treehouse, name)
Steve Hunter
57,712 PointsHi 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
Treehouse Moderator 68,457 PointsI 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.
Steve Hunter
57,712 PointsHa! I hadn't realised I got downvoted for that ... hey ho!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsThat's probably the better solution, to be honest.
josephchemaly
2,914 Pointsjosephchemaly
2,914 PointsThanks steve.