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 Meet Python Create a Variable

write out to the screen The color [YOUR FAVORITE COLOR] is my favorite! Where [YOUR FAVORITE COLOR] is using the var

What am I doing wrong?

using_variables.py
favorite_color = ("blue")
print('The color favorite_color is my favorite!')

2 Answers

Hey Frank,

You are halfway correct! But when naming variables, in this case:

# Remove the brackets and surround your value in either single or double quotes. 
favorite_color = ("blue") 

# Since the value "blue" is stored in variable favorite_color, it needs to be concatenated to the string using the plus sign (+) and a quote (") for spacing. 

# Example: 
car = "lamborgini"
print("In the future, I wish to have a "+car+" as my dream sportscar!") 

# If you want to put your variable at the begginning of a string: 
print(car+ " is the car I want!")

# At the end of a string: 
print("My favorite sportscar is the " +car)    
# Notice we need a puncutation, so: 
print("My favorite sportscar is the " +car+ "!")

Hope this helps, if not let me know.

hey can you explain why, because the video i watched never said to use the + it said to use commas and it never explained how to use it in the middle of a string! the only example i got was using it at the beginning.

SHIVA KUMAR CHANDA
SHIVA KUMAR CHANDA
111 Points

favorite_color = "blue" print('The color is my favorite!')