Membership Operators
Nerd Cafe
What Are Membership Operators in Python?
Operator
Meaning
Example
Step-by-Step Usage
1. Using in with Lists
in with Listsfeatures = ['height', 'weight', 'age']
print('age' in features) # True
print('income' in features) # False2. Using not in with Lists
not in with Listsmodel_params = ['learning_rate', 'max_depth']
print('gamma' not in model_params) # True3. Using with Strings
4. Using with Tuples
5. Using with Dictionaries (Only Keys are Checked)
ML Utility Summary
Use Case
Membership Operator
Example
Keywords
Last updated