相关疑难解决方法(0)

什么是更快的操作,re.match/search或str.find?

对于一次性字符串搜索,使用str.find/rfind比使用re.match/search更快吗?

也就是说,对于给定的字符串s,我应该使用:

if s.find('lookforme') > -1:
    do something
Run Code Online (Sandbox Code Playgroud)

要么

if re.match('lookforme',s):
    do something else
Run Code Online (Sandbox Code Playgroud)

python performance

60
推荐指数
6
解决办法
4万
查看次数

标签 统计

performance ×1

python ×1