[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Testing the data type of a value

On 12-5-2019 09:27, binoythomas1108 at wrote:
> When I run the following code, I get the following output:
>>>> print(type(5))
> class 'int'
> Next, I try to compare the data-type of 5 with the earlier output, I get no output:
>>>> if type(5) == "<class 'int'>":
>          print("Integer")
> Why isn't this working? Advance thanks for your time.
> and regards from
> Binoy


isinstance(object, classinfo)
Return true if the object argument is an instance of the classinfo 
argument, or of a (direct, indirect or virtual) subclass thereof. If 
object is not an object of the given type, the function always returns 
false. If classinfo is a tuple of type objects (or recursively, other 
such tuples), return true if object is an instance of any of the types. 
If classinfo is not a type or tuple of types and such tuples, a 
TypeError exception is raised.