Skip to main content
Practice

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 data type of a variable or value 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

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.