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

using .split for string using (;), how do i do it?

i have variable: available = "banana split;hot fudge;cherry;malted;black and white" and i have been asked to split them using the .split where the semi-colon is (;) and assign this to new variable called sundaes.

how can i do this, i keep getting syntex error??

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes=" banana split:hot fudge:cherry;malted:black and white".split(:)

2 Answers

thanks Carlos, you were right, I was forgetting to use the " " in the (";")

cheers.

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

You have to specify in the "split" function the character that you like to use to split your string, it would be something like this:

>>> available = "banana split;hot fudge;cherry;malted;black and white"
>>> sundaes= available.split(";")

You don't need to re write the string it self, you can use the variable name. I hope that helps you a little bit.