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 trialjeremiah warren
Courses Plus Student 718 Pointscommas and varibles
i dont quite understand variables and how to use them in the middle of a string! could someone explain to me how to use them in more detail please?
1 Answer
Philip Schultz
11,437 PointsHey Jeremiah, Task 1 of 2 is asking you to store your favorite color in a variable called favorite_color. Like so
favorite_color = 'blue' #or what ever color you prefer
For task 2 of 2, it is asking you to use that variable in a sentence. Here are two different ways you can accomplish this. Example 1 - you can separate your strings and variables with commas. Like so,
print("The color ", favorite_color, " is my favorite!")
Example 2 - You can use the format method. This will allow you to insert curly brackets into your string that will be replaced by the variable you put inside of the format method.
print("The color {} is my favorite!".format(favorite_color))
Both ways are acceptable to pass the challenge.