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

Steven Stratton
Steven Stratton
267 Points

.format Challenge Task 2 of 2

I am not sure why my code is not working properly (obviously...).

I assigned my subject to a string with a bracketed variable.

I then tried to reference that variable by using the .format command.

What am I doing incorrectly? Thanks!

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

2 Answers

Feisty Mullah
Feisty Mullah
25,849 Points

Hello, You just need to put .format right after the curly braces. Hope this help. name = 'Steve' subject = "Treehouse loves {}".format(name)

Steven Stratton
Steven Stratton
267 Points

Thank you Isna! I played around with this concept in the work space and saw that they way you cited above works. Additionally, what I have typed above could work if I use subject.format(name) rather than subject.format("name").

Thanks!

Feisty Mullah
Feisty Mullah
25,849 Points

You are welcome Steven, That may worked as well but you do not have to write an extra line of code when you are not asked to do so. :)