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 Collections (Retired) Lists Redux List creation/extension methods

elton coelho
elton coelho
179 Points

what is the optional argument to the str.split()

pls answer

1 Answer

The str.split method has two arguments.

str.split(delimiter=None, maxsplit=-1)
# The delimiter is what you split on and it can be any character. You can split on commas, letters, any chars to my knowledge. It also defaults to splitting on an empty space if no argument is given. 

# The max split argument defaults to -1 which means it'll split on every given delimiter. When an argument >= 0, it will split up to that many times. 

For more information, check out python's docs.

Here is the string.split() method: https://docs.python.org/3.5/library/stdtypes.html#str.split