Muhammad Haseeb Khan
Muhammad Haseeb Khan

Reputation: 965

Is split() function changed

Split function on official python site is as split(pattern, string, maxsplit=0, flags=0)

But when I check it on spyder it is split(sep=None, maxsplit=-1)

Is string argument removed from split() function in python 3.6?

If not then why can't I pass a string arg in it?

Upvotes: 1

Views: 955

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117926

The first split is from the re module

re.split(pattern, string, maxsplit=0, flags=0)

The second is a str method

str.split(sep=None, maxsplit=-1)

The way you call the str.split method is off a str object like the following

>>> s = 'this is a string'
>>> s.split(' ')
['this', 'is', 'a', 'string']

Upvotes: 8

Related Questions