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 59,490 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!!