Testing the data type of a value
Luuk
luuk at invalid.lan
Sun May 12 08:35:34 EDT 2019
On 12-5-2019 10:16, Luuk wrote:
> On 12-5-2019 09:27, binoythomas1108 at gmail.com 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
>>
>
> print(isinstance(5,int))
> True
>
>
> 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.
>
>
After thinking about this, (i am prettry new to python), i was doing this:
>>> print(type(5),type(int),type(5)==type(int),type(5)==int)
<class 'int'> <class 'type'> False True
Can someone explain why type(5)==int evaluates to True ?
--
Luuk
More information about the Python-list
mailing list