Python:为什么列表没有查找方法? [英] Python: Why Lists do not have a find method?
本文介绍了Python:为什么列表没有查找方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I was trying to write an answer to this question and was quite surprised to find out that there is no find method for lists, lists have only the index method (strings have find and index).
有人可以告诉我其背后的理由吗? 为什么字符串都有两者?
Can anyone tell me the rationale behind that? Why strings have both?
推荐答案
我不知道为什么或可能将其埋在某些PEP中,但是我确实知道2种非常基本的查找"列表方法,它们是array.index()
和in
运算符.您总是可以利用这2个来找到您的物品. (此外,重新模块等)
I don't know why or maybe is buried in some PEP somewhere, but i do know 2 very basic "find" method for lists, and they are array.index()
and the in
operator. You can always make use of these 2 to find your items. (Also, re module, etc)
这篇关于Python:为什么列表没有查找方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文