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 String Formatting

Abdallah Abdallah
Abdallah Abdallah
215 Points

formatting function

OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject again.

strings.py
name = "Hey, all practice is good practive, right {}?"
subject = "Treehouse loves {}"
print(subject.format(name))

2 Answers

Steven Parker
Steven Parker
231,007 Points

:point_right: It looks like you printed the result instead of assigning it.

The challenge asks you to "Assign this to the variable subject again." Be sure to assign the formatted string to the variable instead of printing it out!

Try adding the .format function directly to the string on line 2, so the result will get assigned at the same time.

Abdallah Abdallah
Abdallah Abdallah
215 Points

so i should just leave it as subject = "Treehouse loves {} "? it doesnt work

Steven Parker
Steven Parker
231,007 Points

No, you still need to use .format on that string.

Abdallah Abdallah
Abdallah Abdallah
215 Points

I am still quiet unsure how I would solve it. Could you help little bit more?

Steven Parker
Steven Parker
231,007 Points

I don't normally give spoilers, but you are already so close...

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

Notice how this formats the string and assigns it to the variable.

Abdallah Abdallah
Abdallah Abdallah
215 Points

Oh my god so close. I didn't realise you can put the format function after the string like that. I thought you would have to print and add format function on there. Thanks a a lot!