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

formatting.

name = 'dom' subject = 'Treehouse loves {} '.format(name)

In Python 2 : subject = 'Treehouse loves %s' %dom

strings.py
name = 'dom'
subject = 'Treehouse loves {} '.format(dom)

3 Answers

The .format() method in your code is taking the wrong argument.Change it your name variable

name = 'dom'
subject = 'Treehouse loves {} '.format(dom) # <-- here
Ronald Tse
Ronald Tse
5,798 Points

dom is the value ⇒ you should add " ".

If you don't want to use " " (the value), you should directly use the variable name, name

Below 2 codes are the same, make sure you understand the difference between value & variable!!

name = 'dom'
subject = 'Treehouse loves {} '.format(name)
subject = 'Treehouse loves {} '.format('dom')

Hope it helps!!!! Good luck!!

Does the variable dom exist?

Simple answer: No.

Since you didn't put double/single quotes around the text, Python will look for a variable called dom, which, of course doesn't exist.

However, even if you put double quotes around it, the challenge won't expect it. This is because the challenge asked ot you format the name variable, which has you name assigned to it.

Look here:

name = 'dom'
subject = 'Treehouse loves {}'.format(name)

I hope this helps :smile:

~Alex