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 (2015) Python Data Types Strings

use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assing this to subject variable

please help

2 Answers

Eric Haslag
Eric Haslag
9,507 Points

Try this:

name = "Talib"
subject = "Treehouse loves {}".format(name)

first read the question carefully

Eric Haslag
Eric Haslag
9,507 Points

I'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. The format() method will replace occurrences of "{}" in a string with the string representation of the value provided as an argument to the format() 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
Wes Arrington
2,289 Points

Love you man. This small task was killing me he introduces the format method differently in the video... This did the trick. Thanks again.

thank you