About 10,200,000 results
Open links in new tab
  1. python - Determine the type of an object? - Stack Overflow

    2398 There are two built-in functions that help you identify the type of an object. You can use type() if you need the exact type of an object, and isinstance() to check an object’s type against something. …

  2. What's the canonical way to check for type in Python?

    Aug 3, 2014 · In Python, you can use the built-in isinstance() function to check if an object is of a given type, or if it inherits from a given type. To check if the object o is of type str, you would use the …

  3. How can I determine a Python variable's type? - Stack Overflow

    How can I determine a Python variable's type? Asked 16 years, 11 months ago Modified 7 months ago Viewed 4.2m times

  4. Python 3.10+: Optional [Type] or Type | None - Stack Overflow

    Oct 4, 2021 · Łukasz Langa, a Python core developer, replied on a YouTube live related to the Python 3.10 release that Type | None is preferred over Optional[Type] for Python 3.10+.

  5. How to specify multiple types using type-hints - Stack Overflow

    I have a function in python that can either return a bool or a list. Is there a way to specify the types using type hints? For example, is this the correct way to do it? def foo(id) -> list or b...

  6. How to compare type of an object in Python? - Stack Overflow

    In my application code I never need to know the type of something, but it's still useful to have a way to learn an object's type. Sometimes I need to get the actual class to validate a unit test.

  7. python - Subclass in type hinting - Stack Overflow

    In other words, when C is the name of a class, using C to annotate an argument declares that the argument is an instance of C (or of a subclass of C), but using Type[C] as an argument annotation …

  8. python - Getting the class name of an instance - Stack Overflow

    Feb 4, 2009 · How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the inspect module or parse the __class__ attribute.

  9. python - How to check if type of a variable is string? - Stack Overflow

    Jan 30, 2011 · Is there a way to check if the type of a variable in python is a string, like: isinstance(x,int); for integer values?

  10. What type are file objects in Python? - Stack Overflow

    May 22, 2022 · That is because Python frequently uses the notion of 'file-like' objects: Objects that may indeed be something else entirely, but support enough of the file operations for a given purpose -- …