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

后端 未结 2 1308
天命终不由人
天命终不由人 2020-12-13 17:01

I had a string which is stored in a variable myvar = \"Rajasekar SP\". I want to split it with delimiter like we do using explode in PHP.

What is the eq

2条回答
  •  清歌不尽
    2020-12-13 17:18

    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

提交回复
热议问题