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

Maor Beeri
Maor Beeri
2,154 Points

Didn't understand how to write the code in Challenge Task 2 of 2 of "String Formatting" with python. need help...

plus I didn't understand how to assign the subject variable

strings.py
'treehouse loves {}'.format("maor")
name = "maor"
'subject'

3 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Maor,

What this code challenge is asking is to insert the name variable in into a string. We can do by inserting curly braces {} as a placeholder where we want to place our value and then append the format() method to the end of the string like so:

name = "Mike the Frog"
subject = "Treehouse loves {}".format(name)

In your example above you have done something similar with:

'treehouse loves {}'.format("maor")

However the challenge requires for you to place the name value and the string inside variables. Also the order in which they are being called in is incorrect. Here you need to declare your name variable before you can use it :)

Hope that helps!!

Michael Revy
Michael Revy
3,882 Points

name = "maor" print('treehouse loves {}'.format(name))

Maor Beeri
Maor Beeri
2,154 Points

thanks a lot, I figured it out though