Skip to content
Advertisement

why does code following a== type(int) not print even though a is an integer?

This is very basic but somehow I can’t seem to get it;

a = 12345

if a == type(int): 
    print(True)

I also tried replacing int with float, but nothing prints- any idea why??

is a not an integer or float??

Advertisement

Answer

You want

if isinstance(a, int):

What you are doing is comparing an int value to the type of the type int; 12345 == type is never going to be true.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement