Testing the data type of a value
Ben Bacarisse
ben.usenet at bsb.me.uk
Sun May 12 06:41:29 EDT 2019
binoythomas1108 at gmail.com writes:
> 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.
See if this helps...
>>> type(5)
<class 'int'>
>>> type(type(5))
<class 'type'>
>>> type("<class 'int'>")
<class 'str'>
so you are comparing two things with different types. An analogous
situation would be to
>>> print(5)
5
and then to try to compare 5 with the earlier output by writing
if 5 == "5": ...
--
Ben.
More information about the Python-list
mailing list