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 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))

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 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!!