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

.format

If someone could provide with some guidance, it would be much appreciate friend.

strings.py
name = "James"
subject = "Treehouse love '{} ' " ".format (name,)
Victor Warner
Victor Warner
1,882 Points

I'm stuck 2 :

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

Konrad Hunter
Konrad Hunter
3,629 Points

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

{} goes inside the quotes with the rest of the string. You do not need a comma in .format(name) Use commas in between variables if there is more than one in the method.

Victor Warner - You don't appear to be defining your name variable properly. If you put "vic" where the placeholder in name="{}" is and remove your print statements, following the basic structure of the original post you just commented on, you should be okay.

2 Answers

Your line

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

has a few issues that need to be sorted. Firstly, there's an erroneous comma in your format operation. I'm guessing a typo. The placeholder {} also do not require the single quotes around them. In fact, it will error out with them there. The last issue is the extra " at the end of your string. There are two there. I'm guessing that's a typo, or a product of the editor you're using, since that happens to me all the time. If you fix those few issues, you should be able to pass the challenge.

Victor Warner
Victor Warner
1,882 Points

for the one you helped me with it didnt work:

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

I probably am still not doing something right

Victor Warner - yes, you still have the unneeded print call. If you remove everything between the closing " and .format and it will probably pass. I'll point out that the reason we defined name as a variable was to use that inside the format operation, so you should probably use it there :)

dede hurren
dede hurren
11,535 Points

all you need to do is to attach the .format(name) to the end of the string, and have it all saved in the subject variable.