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

Aaron Lawrence
Aaron Lawrence
2,954 Points

I don't really understand the question.

I ran this in the work space and it worked fine, but I'm not sure what they are looking for.

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

3 Answers

Russell Sawyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Russell Sawyer
Front End Web Development Techdegree Student 15,705 Points

Hi Aaron,

Workspaces and the code challenges work a little different. Your code is correct but the challenge wants to see it in a certain format.

name = "Aaron"
subject = "Treehouse loves {}".format(name)
Aaron Lawrence
Aaron Lawrence
2,954 Points

Is there an advantage to the way they wanted it vs what I wrote?

Russell Sawyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Russell Sawyer
Front End Web Development Techdegree Student 15,705 Points

Advantage? not really. But lets take a look at the code Challenge question.

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

The challenge wants you to use .format() on the string "Treehouse loves {}" with your name in the placeholder and assign the entire string to the variable subject. Had you done.

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

Then that would have probably passed the challenge. But

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

is just cleaner.

.