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

name = "RAVITEJA" subject = "Treehouse loves {}" subject = subject.format(name) whats wrong in this code

whats wrong in my code

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

1 Answer

This should work as Python code, but the code challenge is really picky.

Everything you're doing is 100% fine.

The code challenge just expects you to do .format() on the string itself.

Try this:

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

This may be a little confusing, since it is doing two things at once.

Here's what Python is doing behind the scenes:

  1. Python fits in name into the placeholder of the "Treehouse loves {}" string.
  2. Then Python assigns that value to a variable called subject.

I hope you understand now :)

Good luck! ~alex