GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python Exercise: Prints each item and its corresponding type from a list - w3resource

Python Exercise: Prints each item and its corresponding type from a list

Last update on April 17 2025 12:58:31 (UTC/GMT +8 hours)


7. Print Items with Types

Write a Python program that prints each item and its corresponding type from the following list.

Sample List : datalist = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12], {"class":'V', "section":'A'}]

Sample Solution:

Python Code:

# Create a list named 'datalist' containing various data types (int, float, complex, bool, string, tuple, list, dictionary)
datalist = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12], {"class": 'V', "section": 'A'}]

# Iterate through each item in the 'datalist'
for item in datalist:
    # Print the type of each item in the list along with the item itself
    print("Type of", item, "is", type(item)) 
   

Sample Output:

Type of  1452  is  <class 'int'>                                                                              
Type of  11.23  is  <class 'float'>                                                                            
Type of  (1+2j)  is  <class 'complex'>                                                                         
Type of  True  is  <class 'bool'>                                                                             
Type of  w3resource  is  <class 'str'>                                                                        
Type of  (0, -1)  is  <class 'tuple'>                                                                         
Type of  [5, 12]  is  <class 'list'>                                                                          
Type of  {'class': 'V', 'section': 'A'}  is  < class 'dict'> 

Flowchart:

Flowchart: Python program that prints each item and its corresponding type from the following list

For more Practice: Solve these Related Problems:

  • Write a Python program to iterate through a heterogeneous list and print each element along with its data type.
  • Write a Python program to use a for loop and type() function to display the type of each item in a mixed-type list.
  • Write a Python program to create a formatted string that lists each element of a list and its corresponding type.
  • Write a Python program to use list comprehension to produce a list of tuples where each tuple contains an element and its type.

Go to:

  • Python Conditional Statements and loops Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to count the number of even and odd numbers from a series of numbers.
Next: Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.