当前位置: 代码迷 >> 综合 >> python 字符串函数之split()
  详细解决方案

python 字符串函数之split()

热度:26   发布时间:2024-03-08 16:50:17.0

   def split(self, sep,maxsplit): 

       # 功能介绍

        返回字符串中的单词列表,使用sep作为分隔符。
        
          sep 分割字符串的符号。
          默认值是空,表示根据任何空格进行分割。并从结果中丢弃空字符串。
          
          maxsplit 最大分割
          要做的最大拆分次数,-1(默认值)表示没有限制。
          -1(默认值)表示没有限制。

 

>>> message = '18  19  10'.split()
>>> print(message)
['18', '19', '10']

>>> message = '18|19|10'.split('|')
>>> print(message)
['18', '19', '10']

  相关解决方案