python3 判断数据类型

def estType():
    eventList = [1, 'Tom', {'name': 'Lucy', 'age': 16, 'grade': 98}]
    print(type(eventList[0]) is int)
    print(type(eventList[1]) is int)
    print(type(eventList[1]) is str)
    print(type(eventList[2]) is dict)

结果:

True
False
True
True

打印出来的结果是真和假,当然也可以封装成一个标准的函数,传入一个参数,判断其数据类型,返回真假,有时候还是很好用的

原文地址:https://www.cnblogs.com/zrmw/p/10298389.html