Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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