isinstance checks whether a variable has a specified data type and returns True or False. Unlike type hints, which communicate intended inputs without enforcing them, isinstance can validate arguments before a function continues. section 3.4
Validate function inputs
A function that adds integers can check its arguments and raise TypeError when validation fails: def add_v2(a: int, b: int) -> int: if not isinstance(a, int) and not isinstance(b, int): raise TypeError("Inputs must be integers") return a + b This makes the input requirement explicit instead of allowing values such as strings to be concatenated. section 3.4


