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
MUZ140070 Nyasha L. Mupoperi
4,070 Pointshow do i create a new variable named email_greeting that puts treehouse and name into "X loves Y" so X is treehouse and
y is name. i have created the name and treehouse variables already
1 Answer
Mikael Enarsson
7,056 PointsYou should use the .format() method, i.e.:
some_string = "Rainbows"
another_string = "unicorns"
third_string = "{} and {}!".format(some_string, another_string) #third_string is "Rainbows and unicorns!"
Of course, you can replace the content of the string variables with whatever you want!
The '{}' becomes the insertion point for the corresponding argument (i.e., first argument into the first {}, second into the second {} etc.). Also, it can be worth to notice that the arguments don't HAVE to be strings, and that you can use for example integer variables, float variables and, to my knowledge, any kind of class object you would care to!