为什么即使 a 是整数,a== type(int) 后面的代码也不打印?

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

这是非常基础的,但不知何故我似乎无法理解;

a = 12345

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

我也试过用 float 替换 int,但没有打印出来 - 知道为什么吗??

不是整数或浮点数??

你想要

if isinstance(a, int):

您正在做的是将 int 值与 type int 的类型进行比较; 12345 == type 永远不会是真的。