How to test if every item in a list of type 'int'?

后端 未结 7 2000
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 16:21

Say I have a list of numbers. How would I do to check that every item in the list is an int?
I have searched around, but haven\'t been able to find anything on this.

7条回答
  •  执笔经年
    2020-12-08 17:05

    See functions

    def is_int(x):
        if type(x) == int:
            return True
        return
    
    
    def all_int(a):
        for i in a:
            if not is_int(i):
                return False
        return True
    

    Then call

    all_int(my_list) # returns boolean
    

提交回复
热议问题