CPython中的字符串'in'运算符

问题描述 投票:0回答:1

据我了解,当我在Python中执行'foo' in 'abcfoo'时,解释器会尝试在后台调用'abcfoo'.__contains_('foo')

这是string matching(又名搜索)操作,它接受多种算法,例如:

enter image description here

我怎么知道给定实现可能使用哪种算法? (例如,带有CPython的Python 3.8)。我无法查看这些信息,例如the source code用于CPython的字符串。我不熟悉其代码库,例如我找不到为此定义的__contains__

python python-3.x string algorithm cpython
1个回答
2
投票

根据source code

© www.soinside.com 2019 - 2024. All rights reserved.