Membership operator - "in":
-
The in operator called on a dictionary instance tests whether a given key is present in a dictionary.
-
If the value is present in the sequence it returns True. It returns False otherwise.
-
The behaviour of in operator is the opposite of the not in operator.
Example 1:
# Example Python program that finds |
Output:
Token with value "switch" is not found |
Example 2:
# Example Python program that checks fruitPrices = {"Apples":1.42, fruit2Lookup = "Grapes"; if fruit2Lookup in fruitPrices: |
Output:
Grapes not available |