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 (2015) Python Data Types String concatenation

I need help

OK! Make a new variable named subject that concatenates (uses the + sign) the string "Treehouse loves" and your name variable. You've probably received an email or two with this subject already!

I typed in the first variable . Then after that I do not know how to do this ..?

strings.py
name = 'Alwi' + 'Shaik' + ' Delgado' + ' Alaudin'
subject = 'Treehouse Love'
str('subject'+'name")

1 Answer

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

Hi! If you put a piece of text inside quotes (either single or double quotes, just be consistent), Python reads that as a string value (a string "literal"), which can be assigned to ("stored in") a variable. The task is to assign your name as a string to a variable called name. In the next step, concatenate this string (stored in the name variable) with the string 'Treehouse loves', and store the result in a variable called subject. You can concatenate string literals as well as variables referring to those strings.

# note: you don't have to put together your name
# from separate parts for this task
name = 'Alwi Shaik Delgado Alaudin'
# the first element is a string literal, the second element is
# the variable 'name' which refers to a string
subject = 'Treehouse loves' + name  
# the 'subject' variable's value will be the string
# 'Treehouse lovesAlwi Shaik Delgado Alaudin'