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 trialtalib faridy
299 Pointsuse .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assing this to subject variable
please help
2 Answers
Eric Haslag
9,507 PointsTry this:
name = "Talib"
subject = "Treehouse loves {}".format(name)
talib faridy
299 Pointsthank you
talib faridy
299 Pointstalib faridy
299 Pointsfirst read the question carefully
Eric Haslag
9,507 PointsEric Haslag
9,507 PointsI'm sorry, I'm not exactly sure what the question is. I can try to explain what's going on... hopefully that will help.
format()
is a method that can be called on strings to substitute in a value for a placeholder. This is known as string interpolation. Theformat()
method will replace occurrences of "{}" in a string with the string representation of the value provided as an argument to theformat()
method.In this example, we're substituting in someone's name in the "Treehouse loves {}" string in place of the curly braces ("{}"). In the code above, the
subject
variable will contain the string "Treehouse loves Talib".The
format()
method can receive more than one argument to substitute in strings for multiple placeholders. The Python documentation for string formatting here has more details.Wes Arrington
2,289 PointsWes Arrington
2,289 PointsLove you man. This small task was killing me he introduces the format method differently in the video... This did the trick. Thanks again.