Guidelines

How to Check Variable and Value Types

The type() function is used to check the type of a variable or value.


How to Use the type() Function

The type() function returns the type of the data when a variable or value is passed inside the parentheses.

Using the type() Function
number = 10 # Assign integer 10 to variable number print(type(number)) # <class 'int'> : Integer type text = "Python Programming" # Assign string to variable text print(type(text)) # <class 'str'> : String type

Checking Types

The type() function can check the type of all basic data types and user-defined types in Python.

Checking Various Data Types
is_active = True print(type(is_active)) # <class 'bool'> : Boolean type my_list = [1, 2, 3] print(type(my_list)) # <class 'list'> : List type my_dict = {"key": "value"} print(type(my_dict)) # <class 'dict'> : Dictionary type
Mission
0 / 1

Which of the following is a correct description of the type() function?

This function prints a variable or value.

This function deletes a variable or value.

This function checks the data type of a variable or value.

This function sorts a variable or value.

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result