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 trialDavid Tovar
67 Pointsprint("the color" favorite_color=("blue") "is my favorite color!") In need of some help with task #2 please!
favorite_color= ("blue")
print("the color" favorite_color=("blue") "is my favorite color!")
2 Answers
Steve Hunter
57,712 PointsHi 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.
Tlotlo Molokwe
16,618 Pointsyour 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