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

Hey i'm really struggling to get this, i'm probably so close but can someone help me.

OK, now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject (so start with subject =).

strings.py
name = "Danny"
subject = "Treehouse loves {}.format(Danny)

3 Answers

Christian Mangeng
Christian Mangeng
15,970 Points

Hi Danny,

two things need to be changed:

1) The closing " is missing in subject. The string should end right before the .format.

2) Format the subject string directly with your name variable. If you wanted to format it with what's assigned to this variable (i.e. your name), you would have to format it with the string "Danny", instead of a variable Danny.

Good luck

Matt Coston
Matt Coston
18,425 Points

yea using dot syntax right after a string is so weird looking to me.

Thank you for the reply, i was closer than i thought. I see now i was trying to use the "Danny" string instead of the "name" variable. A few things i've been stuck on because i am thinking about them too much when the answer is in plain sight.

Thanks again for the help!

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The "dot after a string" thing really depends on use case. If a string is only going to be used in one place, go ahead and call whatever methods you need after it. If the string is going to be used more, assign it to a variable and then use the variable. In this case, and in more cases than you might guess, you'll only use the string once so you'll call the methods directly on it.

There are very few real hard-and-fast rules in programming. Welcome to the world of shruggies ¯\_(ツ)_/¯ .

khai ellington
PLUS
khai ellington
Courses Plus Student 834 Points

This is one of those things that dissapoints me about this track. Like Matt mentioned, using the .format right after a string makes little sense to someone like me, who has no idea what these strings do in the grand scheme of things. It seems silly, and I can only assume doing something like this would never be required in the "real world", but its a shame how none of this is really explained. at all.

If i had a slightly deeper understanding, (which i do know thanks to other information sources) I wouldnt have half the struggle I currently do with Python.