有两个办法,直接上代码
# 方法一,使用isinstance
a = 5.0
if isinstance(a,int):
print('is int')
elif isinstance(a,float):
print('is float')
else:
print('is other')
# 方法二,通过与其他已知类型的常量进行对比
a = 5.0
if type(a) == type(1):
print('is int')
elif type(a) == type(1.0):
print('is float')
else:
print('is other')