描述

Python split() 方法通过指定分隔符对字符串进行分割并返回一个列表,默认分隔符为所有空字符,包括空格、换行(\n)、制表符(\t)等。

语法

split() 方法语法:

S.split([sep=None][,count=S.count(sep)])

参数

  • sep -- 可选参数,指定的分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
  • count -- 可选参数,分割次数,默认为分隔符在字符串中出现的总次数。

返回值

返回分割后的字符串列表。

实例

以下实例展示了 split() 方法的使用方法:

#!/usr/bin/python3

S = "this is string example....wow!!!"
print (S.split( ))
print (S.split('i',1))
print (S.split('w'))

以上实例输出结果如下:

['this', 'is', 'string', 'example....wow!!!']
['th', 's is string example....wow!!!']
['this is string example....', 'o', '!!!']

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2021-07-22
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2022-03-06
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案