warship warship - 6 months ago 11
Python Question

Type of all elements in Python list

Is there a way to quickly print out the type of all the elements of some given list in Python?

For example

[1, 2, 3.5]
would give
int, int, float
.

The closest existing resource I've found to answering my question is: Test type of elements python tuple/list, which just gives holistic True/False outputs (which is not what I'm looking for).

Leb Leb
Answer

Try the following:

for l in lst:
    print(type(l))

Where lst = [1,2,3.5]