【Python】如何判断变量类型

发布时间 2023-11-30 22:38:10作者: NotReferenced

1、isinstance

用法:

if(isinstance(var, Type)):
    pass

2、is + class

用法:

if(a.__class__ is VarType):
    pass

3、type + is

用法:

if(type(var) is VarType):
    pass