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

not getting exactly what to do in this

i tried this code many times but not getting whats the actual error

name = "Anurag"
subject = ("Treehouse loves Anurag". format ("anurag"))

1 Answer

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,862 Points

HI Amarjeet,

Let's look at the challenge text that tells us exactly what we need to do:

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

And let's compare to your code. The instructions say to use the string "Treehouse loves {}". Your string is "Treehouse loves Anurag".

Next, we need to use the format() method. The instructions say to use the name variable. You have used the string literal 'Anurag'.

In addition, you've added some spaces where they don't belong. For example, format is a method on a string. The syntax for methods is the object name, then a period, then the method name. No spaces. Similarly, you've added a space between the method name and the opening parenthesis. The Python parser will accept this latter space, but it does violate the Python style guide.

Hope that clears everything up.