How to check if something is (not) in a list in Python?

Sometimes, we want to check if something is (not) in a list in Python.

In this article, we’ll look at how to check if something is (not) in a list in Python.

How to check if something is (not) in a list in Python?

To check if something is (not) in a list in Python, we can use the not in operators.

For instance, we write

3 not in [2, 3, 4]

to check if 3 isn’t in [2, 3, 4].

It should return False since 3 is in [2, 3, 4].

Conclusion

To check if something is (not) in a list in Python, we can use the not in operators.