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
打印出來的結果是真和假,當然也可以封裝成一個標准的函數,傳入一個參數,判斷其數據類型,返回真假,有時候還是很好用的