Python Tutorials · Python Operators

Membership Operators

Learn all about Membership Operators in this comprehensive tutorial.

5 min read beginner
  • Membership operators are used to test if a sequence is presented in an object:
  • The membership operators also work with strings:

Membership Operators

Membership operators are used to test if a sequence is presented in an object:

OperatorDescriptionExampleTry it
inReturns True if a sequence with the specified value is present in the objectx in yTry it »
not inReturns True if a sequence with the specified value is not present in the objectx not in yTry it »

Examples

python
python

Membership in Strings

The membership operators also work with strings:

python

Module quiz

2 questions
1

Which of the following is true about Membership Operators?

2

What is the most common pitfall when working with Membership Operators?

Answer all questions to submit.