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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM