isinstance()
is your friend here. It returns a boolean and can be used in the following ways to check types.
if isinstance(obj, (int, long, float, complex)):
print obj, "is a built-in number type"
if isinstance(obj, MyClass):
print obj, "is of type MyClass"
More Related Contents:
- Getting an instance name inside class __init__() [duplicate]
- python assign values to list elements in loop
- Why doesn’t assigning to the loop variable modify the original list? How can I assign back to the list in a loop? [duplicate]
- How to access object attribute given string corresponding to name of that attribute
- How to build a basic iterator?
- How do you programmatically set an attribute?
- Spawning multiple instances of the same object concurrently in python
- Saving and loading multiple objects in pickle file?
- Is everything an object in Python like Ruby?
- python class instance variables and class variables
- super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object
- Python dictionary from an object’s fields
- Accessing Object Memory Address
- Elegant way to check if a nested key exists in a dict?
- How can I separate the functions of a class into multiple files?
- Using self.xxxx as a default parameter – Python
- Difference between ‘cls’ and ‘self’ in Python classes?
- Evaluation of boolean expressions in Python
- Getting container/parent object from within python
- What does object’s __init__() method do in python? [duplicate]
- Retrieving JSON objects from a text file (using Python)
- How to access (get or set) object attribute given string corresponding to name of that attribute
- How to clone a Python generator object?
- “_set” in a queryset object in Django
- How to make a copy of a 2D array in Python? [duplicate]
- Python : Assert that variable is instance method?
- Python object attributes – methodology for access
- What’s the difference between the square bracket and dot notations in Python?
- In Python, when are two objects the same?
- TypeError: Missing one required positional argument [duplicate]