Python: lists .remove(item) but not .find(item) or similar?
This question already has an answer here:
Interesting that it's not list.find
, but list.index
:
>>> l = ['a', 'b', 'c']
>>> l.index('c')
2
To test for membership:
>>> 'b' in l
True
Which is equivalent to (and should be used instead of):
>>> l.__contains__('b')
True
链接地址: http://www.djcxy.com/p/28122.html
上一篇: 在字符串中查找单词的位置