Account
Categories

IN Operator (in) in Python


Definition:

It checks if a value is present in a sequence. If it is present, it returns True. Otherwise, it returns False.

Now you will clearly understand with the help of the diagram.

a (value) ────────────────┐
                          ↓
                  ┌─────────────┐
                  │     1, 2    │  ← (sequence / object)
                  └──────┬──────┘
                         │
                 Here, the value 1 is present in the sequence.
  

Syntax:

a in b

Example:

a = 1
b = [1, 2]

print(a in b)

Output:

True