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

Cordell Key
Cordell Key
1,130 Points

Help with Python - String Challenge

Why can I not run this code, I believe it may be the syntax?

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

strings.py
name = 'Cordell' 
subject = "Treehouse loves { }" 
print(subject.format(name)) 

4 Answers

If you remove the space inside the {} it should work :)

Cordell Key
Cordell Key
1,130 Points

Hi Bryan - Sorry removing the space from {} did not work, but I appreciate the help!

Strange, this worked for me:

name = 'Cordell' 
subject = "Treehouse loves {}" 
print(subject.format(name)) 
Arindam Roychowdhury
Arindam Roychowdhury
3,244 Points

"Treehouse loves {name}".format(**{'name':name})

Note the **

>>> name = 'Cordell'
>>> subject = "Treehouse loves { }"
>>> subject.format(**{'name':name})
'Treehouse loves Cordell'
Cordell Key
Cordell Key
1,130 Points

Hi Arindam - Thanks for the help, one the "**" why are these needed? I haven't learned this syntax yet.

Cordell Key
Cordell Key
1,130 Points

I just ran my code in Workspace to see if would run, and it did without any problems.

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