Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *