Skip to main content
 首页 » 编程设计

python之split() 函数是否更改

2025年05月04日15bluestorm

官方 python 站点上的拆分函数如下 split(模式, 字符串, maxsplit=0, flags=0)

但是当我在 spyder 上检查它时,它是 split(sep=None, maxsplit=-1)

是否从 python 3.6 中的 split() 函数中删除了字符串参数?

如果不是那么为什么我不能在其中传递一个字符串参数?

请您参考如下方法:

第一个拆分来自re module

re.split(pattern, string, maxsplit=0, flags=0) 

第二个是 str method

str.split(sep=None, maxsplit=-1) 

调用 str.split 方法的方式是关闭 str 对象,如下所示

>>> s = 'this is a string' 
>>> s.split(' ') 
['this', 'is', 'a', 'string']