Python string.replace/.strip/.find和内置函数之间是否存在差异?
我有一个Python 2代码库,我正在将其迁移到Python 3。旧的代码库使用Python string.replace/.strip/.find和内置函数之间是否存在差异?,python,python-3.x,python-2.7,python-2to3,Python,Python 3.x,Python 2.7,Python 2to3,我有一个Python 2代码库,我正在将其迁移到Python 3。旧的代码库使用 import string foo = string.replace(s, old, new) foo = string.strip(s) foo = string.find(s, sub, start, end) 我用2to3移动了它,但这给出了一个错误。我的猜测是,我必须用 foo = s.replace(old, new) foo = s.strip() foo = s.find(sub, start,
import string
foo = string.replace(s, old, new)
foo = string.strip(s)
foo = string.find(s, sub, start, end)
我用2to3移动了它,但这给出了一个错误。我的猜测是,我必须用
foo = s.replace(old, new)
foo = s.strip()
foo = s.find(sub, start, end)
我查看了文档:
- vs
- vs
- vs
字符串模块中?这是Python 2.7之前的一个变化吗?可能存在性能差异,或者某些特殊情况的处理方式不同吗?从性能上看,它们是方法调用的简单包装。这在更老的Python中可能有所不同。根据相同代码的初始注释:
从Python1.6开始,这些函数中的许多都实现为
标准字符串对象上的方法
从上下文判断,它们是方法调用的简单包装。这在更老的Python中可能有所不同。根据相同代码的初始注释:
从Python1.6开始,这些函数中的许多都实现为
标准字符串对象上的方法