Editor settings

General settings

Save settings

Learn to program with Python

Checking the type of an object #

The type() function is used to determine the class or type of an object. When you pass an object to the type() function, it returns the class that was used to create that object. In the example below, we could see that both my_string and other_string are created from the class str.

my_string = str("Hello, World!")
other_string = "Hello, World!"

print(type(my_string)) # <class 'str'>
print(type(other_string)) # <class 'str'>

Exercise #

  • Assign the type of an_object to the variable type_of_object

Tests #

  • type_of_object should be the class list
Output will be displayed here