How to check the type of the elements of a list in Python?

1

I have a list of data, and I need to verify that all elements are integers or string , or any other data type. Is it possible to check all the elements or need to be one by one?

For example:

Lista = [0,1,2,3,4,5,6,"7"]

I need a function that tells me whether they are all integers or not.

    
asked by anonymous 19.01.2018 / 14:13

1 answer

3

I could do this:

all(isinstance(n, int) for n in lista)

Something is already ready ( isinstance() and all() ).

Font .

    
19.01.2018 / 14:18