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!

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

james tyson
james tyson
1,302 Points

i am really confused on how i am suppost to out the format i am useing it in this sense subject.format("Treehouse loves

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

name  = "deja vu, huh?"
subject.format("Treehouse loves {}",(subject = name))

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,404 Points

You've got all the parts, but in a jumbled order. Let's break down this task:

OK, now use .format() on the string "Treehouse loves {}"....

.format() is a string method, which means it needs to operate directly on a string or a variable pointing to a string:

"Treehouse loves {}".format()

to put your name into the placeholder.

The placeholder, also called a replacement field, is marked by the curly brackets {}. The arguments to the format method are used, in order, to fill in each replacement field. If more than one, the arguments are separated by a comma.

"Treehouse loves {}".format(name)

Assign this to the variable subject (so start with subject =).

The format method takes a string and returns a new string. To save this new string, it needs to be assigned to a variable. Do this by prepending the code statement above with subject =.

Post back if you need more help. Good luck!!