Split a string only by first space in python

后端 未结 3 931
Happy的楠姐
Happy的楠姐 2020-11-30 07:23

I have string for example: \"238 NEO Sports\". I want to split this string only at the first space. The output should be [\"238\",\"NEO S

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 07:37

    Just pass the count as second parameter to str.split function.

    >>> s = "238 NEO Sports"
    >>> s.split(" ", 1)
    ['238', 'NEO Sports']
    

提交回复
热议问题