What’s the canonical way to check for type in Python?
Use isinstance to check if o is an instance of str or any subclass of str: if isinstance(o, str): To check if the type of o is exactly str, excluding subclasses of str: if type(o) is str: Another alternative to the above: if issubclass(type(o), str): See Built-in Functions in the Python Library Reference for relevant … Read more