1

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?

1 Answers1

8

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']
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • How can I use re module and if I want to pass more than one delimiter in str's split() then how can I achieve it? – Muhammad Haseeb Khan Mar 09 '17 at 14:36
  • [This post](https://stackoverflow.com/questions/1059559/split-strings-with-multiple-delimiters) should answer both of those questions. So will [this one](https://stackoverflow.com/questions/4998629/python-split-string-with-multiple-delimiters) – Cory Kramer Mar 09 '17 at 14:37
  • It means in str.split() we are limited with only one delimiter. Am I right. because all the answers used re module. – Muhammad Haseeb Khan Mar 09 '17 at 14:42