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 Use .split() and .join()

Kelly Holbrook
seal-mask
.a{fill-rule:evenodd;}techdegree
Kelly Holbrook
Front End Web Development Techdegree Student 1,189 Points

I'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!!

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}."
display_menu = ", ".join(sundaes)

1 Answer

Hi 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!

No problem!