Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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