0
0
Pythonprogramming~15 mins

Type checking using type() in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Type Checking Using type()
📖 Scenario: You are working on a program that needs to handle different types of data carefully. Sometimes, you need to check what type of data you have before doing something with it.
🎯 Goal: Build a simple Python program that creates different variables, checks their types using the type() function, and prints the results.
📋 What You'll Learn
Create variables of different types: integer, string, and list
Create a variable called data_type to store the type of a variable
Use type() to find the type of each variable
Print the type of each variable
💡 Why This Matters
🌍 Real World
Type checking helps programs handle data correctly, avoiding errors when working with different kinds of information.
💼 Career
Many programming jobs require understanding data types to write safe and bug-free code.
Progress0 / 4 steps
1
Create variables of different types
Create three variables: number with the value 10, text with the value 'hello', and items with the value [1, 2, 3].
Python
Need a hint?

Use simple assignment to create each variable with the exact values.

2
Create a variable to hold the type
Create a variable called data_type and set it to None as a placeholder.
Python
Need a hint?

This variable will store the type information later.

3
Use type() to find the type of each variable
Use the type() function to find the type of number, text, and items. Assign the type of number to data_type. Then create variables text_type and items_type to store the types of text and items respectively.
Python
Need a hint?

Use type(variable) to get the type of each variable.

4
Print the types of the variables
Print the values of data_type, text_type, and items_type each on a separate line.
Python
Need a hint?

Use three print() statements to show the types.