How to check if an element exists in a Python array (Equivalent of PHP in_array)?

我只是一个虾纸丫 提交于 2019-12-10 12:44:29

问题


I'm new to Python and I'm looking for a standard function that would tell me if an element is present in an array. I found the index method but it throws an exception if the element is not found. I just need some simple function that would return true if the element is in the array or false if not.

Basically an equivalent to PHP in_array.


回答1:


>>> 1 in [0, 1, 2, 3, 4, 5]
True


来源:https://stackoverflow.com/questions/14743156/how-to-check-if-an-element-exists-in-a-python-array-equivalent-of-php-in-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!