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

Need help using the .format to add variable name to a string

What am I doing wrong?

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

Took away the parenthesis and it says: Be sure to use the {} placeholder and the .format() method.

name = "Jonathan" subject= "Treehouse loves {}" subject.format(name)

3 Answers

Thanks James!

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you don't need the parens () around subject and it may want you to do it all in one line, subject = .......format(arg) instead of defining subject on one line then using format on the next like you have.

tried but didn't work

Norman OBrient
PLUS
Norman OBrient
Courses Plus Student 288 Points

Hello Jonathan, I am having the same problem - maybe something is going on with the site...

Need help on string formatting exercise in Python Basics using the .format method. I cannot get the challenge to pass me on even though I have successfully achieved the task in the console. Here is the code I wrote:

name = "Norman" subject = "Treehouse loves {}".format(name) Treehouse loves Norman

I also tried the following code which worked but the challenge did not accept

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

Ill let you know if i get an answer - please do the same if you find out. All the best! Norman

This is what I wrote and it worked: available = "banana split;hot fudge;cherry;malted;black and white" sundaes = available.split(';') menu = "Today's flavors are: {}.".format(", ".join(sundaes))