Python Membership Operators
1. What are Membership Operators?
Membership operators are used to check whether a value is present in a group.
In simple words:
π They check βIs this item inside that group?β
Python has two membership operators:
-
in -
not in
2. The in Operator
in returns True if the value exists in the group.
Example with String
Output:
Example with List
Example with Tuple
3. The not in Operator
not in returns True if the value does NOT exist in the group.
Example
Output:
4. Membership Operators with if Statement
Example
Another Example
5. Membership Operators with User Input
Example
6. Membership in Dictionary (Keys Only)
Membership operators check keys, not values.
Example
Output:
7. Common Beginner Mistakes
β Checking Value Instead of Key
β Correct:
β Wrong Case in String
Output:
Strings are case-sensitive.
8. Simple Practice Examples
Example 1: Check Letter
Example 2: Check Number in List
Example 3: Email Check
9. Summary (Membership Operators)
β Used to check presence
β in means exists
β not in means not exists
β Works with string, list, tuple, dictionary
β Very useful in conditions
π Perfect for Beginner eBook
This chapter is ideal for:
-
Python beginner books
-
School & college students
-
Self-learners
If you want next, I can write:
-
Bitwise Operators
-
Operator Exercises
-
ifβelse statements
-
Loops (for, while)
-
MCQs with answers
Just tell me π
