split()方法

https://www.runoob.com/python3/python3-string-split.html


str.split(str="", num=string.count(str))
  • str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
  • num -- 分割次数。默认为 -1, 即分隔所有。

例子:

str = "this is string example....wow!!!"

print (str.split( )) # 以空格为分隔符

print (str.split('i',1)) # 以 i 为分隔符

print (str.split('w')) # 以 w 为分隔符

结果:

['this', 'is', 'string', 'example....wow!!!']
['th', 's is string example....wow!!!']
['this is string example....', 'o', '!!!']
 
posted @ 2022-09-20 15:13  yinghualeihenmei  阅读(31)  评论(0)    收藏  举报