Python has a function for the in operator

Is there any Python function for the "in" operator, for example, what we have for operator.lt, operator.gt, .. I will not use this function to do something like:

operator.in(5, [1,2,3,4,5,6]) >> True operator.in(10, [1,2,3,4,5,6]) >> False 
+6
source share
1 answer

Yes, use operator.contains() ; note that the operand order is canceled:

 >>> import operator >>> operator.contains([1,2,3,4,5,6], 5) True >>> operator.contains([1,2,3,4,5,6], 10) False 

You may have missed a handy mapping table at the bottom of the documentation.

+10
source

Source: https://habr.com/ru/post/971542/


All Articles