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 trialShalin Gadhavi
513 Pointshow to make a variable
I am confused between strings and variables
name="Shalin"
subject ="""'Treehouse loves ' + name"""
2 Answers
Paul Cox
12,671 PointsBasically a variable is where you store the string (known as a literal because it is a fixed value). So in the example, name without quotes is a variable, whereas "name" would be a string literal with the value "name".
name = "Shalin"
subject = "Treehouse loves " + name
Oluwatobi Popoola
10,447 PointsThe first name declaration is great, although the subject string is a bit jumbled.
There is no need for additional quotes when you want to create a simple string message, just two is necessary.
And since name is a variable that you have set to a value, you leave it outside the quotes.
Example:
name = "Tobi" message = "Hi, my name is " + name