close

How to print types within a list

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to print types within a list in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to print types within a list?

  1. How to print types within a list?

    Essentially, the type function takes an object and returns the type of it. Try the below code:
    for item in [1,2,3, 'string', None]: print type(item)

  2. print types within a list

    Essentially, the type function takes an object and returns the type of it. Try the below code:
    for item in [1,2,3, 'string', None]: print type(item)

Method 1

ls = [type(item) for item in list_of_items]
print(ls)

Method 2

Essentially, the type function takes an object and returns the type of it. Try the below code:

for item in [1,2,3, 'string', None]:
    print type(item)

Output:

<type 'int'>
<type 'int'>
<type 'int'>
<type 'str'>
<type 'NoneType'>

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read