What is for Python what 'explode' is for PHP? What is for Python what 'explode' is for PHP? python python

What is for Python what 'explode' is for PHP?


Choose one you need:

>>> s = "Rajasekar SP  def">>> s.split(' ')['Rajasekar', 'SP', '', 'def']>>> s.split()['Rajasekar', 'SP', 'def']>>> s.partition(' ')('Rajasekar', ' ', 'SP  def')

str.split and str.partition


The alternative for explode in php is split.

The first parameter is the delimiter, the second parameter the maximum number splits. The parts are returned without the delimiter present (except possibly the last part). When the delimiter is None, all whitespace is matched. This is the default.

>>> "Rajasekar SP".split()['Rajasekar', 'SP']>>> "Rajasekar SP".split('a',2)['R','j','sekar SP']