We use membership operators to check whether a value or variable exists in a sequence (string, list, tuples, sets, dictionary) or not.
Operator | Syntax | Description | Example |
---|---|---|---|
in | x in y | This returns True if x exists in sequence in y |
x = "Hello, World!" |
not in | x not in y | This returns True if either x does not exist in sequence in y |
x = "Hello, World!" print("hello" not in x) |
Example
Use the operators to solve for the following equations.
1. Is 200 in "200 years ago?"
2. Is "apples" in this list ["apple", "bananas", "cherries"]
3. "et" is not in "Let's go for a meal!" True or False?