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

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