#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Membership operators work across multiple types of containers """ from typing import List """ in Evaluates to True if it finds a variable in the specified sequence and False otherwise. """ x: List[int] = [3, 2, 1] print(3 in x) print(5 in x) mystring: str = "hey there" print("hey" in mystring) print("nothere" in mystring) """ not in Evaluates to True if it does not finds a variable in the specified sequence and False otherwise. """ x = [3, 2, 1] print(3 not in x) print(5 not in x) mystring = "hey there" print("hey" not in mystring) print("nothere" not in mystring) # %% Empty containers evaluate to False when tested or cast into bool # None, 0, and empty strings/lists/dicts/tuples all evaluate to False. # All other values are True print(bool(None)) # => False print(bool(0)) # => False print(bool("")) # empty string print(bool([])) # empty list print(bool(())) # empty tuple print(bool(set())) # empty set print(bool({})) # empty dict print("This will be helpful to remember when using if statements and loops!")