简体   繁体   中英

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??

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM