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

The print function keeps turning yellow as if it's trying to become a script. I am beyond confused. Any suggestions?

Trying to do this:

1 favorite_color = ("green") 2 print ("The color") favorite_color ("is my favorite!")

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

2 Answers

Steven Parker
Steven Parker
231,271 Points

You don't need parentheses around the value you assign to the variable, and you need only one set around all the arguments to "print". The arguments inside should be separated with commas.

favorite_color = "green"
print("The color", favorite_color, "is my favorite!")
Christopher Gardner
Christopher Gardner
12,719 Points

On top of what Steven Parker said, you can also use conjugation, like so:

favorite_color = "green"
print("The color " + favorite_color + " is my favorite!")

Notice that you have to include spaces in the strings (like after the word color, and before is in the last string) if you want them to show when you print.

Steven Parker
Steven Parker
231,271 Points

I think the word you were looking for is concatenation. :wink:

Christopher Gardner
Christopher Gardner
12,719 Points

Steven Parker Thanks for the catch! Can't believe I did that, haha.

i was stuck on that question too thx