首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
V2EX 提问指南
广告
V2EX
›
问与答
python 里面检查'ab'是否在 str 字符串里面: str.find('ab') > -1; 'ab' in str;哪个更好呢?
hao1032
·
2015-07-14 11:48:33 +08:00
· 2188 次点击
这是一个创建于 3367 天前的主题,其中的信息可能已经有所发展或是发生改变。
我现在经常使用‘ab’ in str,只是因为这样写好看一点。不知道这样做是不是对的。
str
字符串
str.find
1 条回复
•
2015-07-14 11:51:57 +08:00
1
yjmade
2015-07-14 11:51:57 +08:00
In [11]: %timeit a.find("ab")
1000000 loops, best of 3: 312 ns per loop
In [13]: %timeit "ab" in a
10000000 loops, best of 3: 72.3 ns per loop
明显 in 更好 啊
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
2032 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms ·
UTC 03:29
·
PVG 11:29
·
LAX 20:29
·
JFK 23:29
Developed with
CodeLauncher
♥ Do have faith in what you're doing.