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 trialJonathan Hamada
4,810 PointsNeed help using the .format to add variable name to a string
What am I doing wrong?
name = "Jonathan"
subject = ("Treehouse loves {}")
subject.format(name)
3 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou don't put subject again, just "the string with the {}".format(value that goes in the hole).
Jonathan Hamada
4,810 PointsThanks James!
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou 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.
Jonathan Hamada
4,810 Pointstried but didn't work
Norman OBrient
Courses Plus Student 288 PointsHello 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
Jonathan Hamada
4,810 PointsThis 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))
Jonathan Hamada
4,810 PointsJonathan Hamada
4,810 PointsTook away the parenthesis and it says: Be sure to use the
{}
placeholder and the.format()
method.name = "Jonathan" subject= "Treehouse loves {}" subject.format(name)