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_objectto the variabletype_of_object
Tests #
type_of_objectshould be the classlist
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules