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 trialKelly Holbrook
Front End Web Development Techdegree Student 1,189 PointsI'm having issues reassigning menu and using .format()
Hello, I am very new to Python. I am having minor issues trying to figure out how to use .format() Any help is greatly appreciated! Thanks!!
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}."
display_menu = ", ".join(sundaes)
1 Answer
Katie Wood
19,141 PointsHi there!
You're on the right track - you've correctly assigned display_menu's value, but in order to use it in .format, it needs to be before the menu line, like this:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
display_menu = ", ".join(sundaes)
menu = "Our available flavors are: {}."
Then, you can add your .format() after the menu string, to replace the {} with the contents of display_menu:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
display_menu = ", ".join(sundaes)
menu = "Our available flavors are: {}.".format(display_menu)
In case you're curious, the challenge also mentions being able to do the join and format in the same line with menu - that looks like this:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}.".format(", ".join(sundaes))
With .format, you basically have a string value that includes curly braces {}. When you add .format to that string, the parentheses contain whatever you want to replace those curly braces with. If you have more than one set of curly braces in the string, you would put a value for each one in the parentheses, like this:
example = "{} is learning to program in {}".format("Katie", "Python") #"Katie is learning to program in Python"
Hope this helps!
Kelly Holbrook
Front End Web Development Techdegree Student 1,189 PointsKelly Holbrook
Front End Web Development Techdegree Student 1,189 PointsYou're the best! Thank you so much for your help Katie!
Katie Wood
19,141 PointsKatie Wood
19,141 PointsNo problem!