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

print("the color" favorite_color=("blue") "is my favorite color!") In need of some help with task #2 please!

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

2 Answers

Hi David,

To 'interpolate' a variable value into a string, you use the {} braces. The value held by the variable, in this case favorite_color is inserted there. The value to insert is passed into the format() method and that, in turn, is chained to the string containing the braces.

my_name = "Steve"
print("My name is {} and I live in the UK".format(my_name))

So here, the content of my_name is inserted in the output string where the braces are placed. The variable is passed into format().

I hope that helps,

Steve.

your print statement should be something like: print("the color {} is my favorite color!".format(favorite_color))

also you don't need the brackets around "blue" for the favorite_color variable