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()

Akhila Jana
PLUS
Akhila Jana
Courses Plus Student 577 Points

How do I edit an existing string variable by using the variable name?

I'm trying to change the string value by using the variable name. But the value seems to be unaffected.

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

1 Answer

Steven Parker
Steven Parker
231,271 Points

I'm not sure which variable you are referring to. But from the standpoint of the challenge, you did a little bit too much on the third line. You don't need "format" there, just assign the template string by itself to "menu".

Everything else looks good, so with that change you should pass the challenge.

Akhila Jana
Akhila Jana
Courses Plus Student 577 Points

I want to modify menu variable. I want to display string separated by commas instead of a list

Steven Parker
Steven Parker
231,271 Points

The "join" line makes a string separated by commas instead of a list, and puts it into "display_menu". Then the final line uses that string on the template and puts the final string into "menu".