warship warship - 2 years ago 68
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 Source

Try the following:

for l in lst:

Where lst = [1,2,3.5]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download