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