type()
Published Apr 12, 2022Updated Jul 11, 2022
Contribute to Docs
The type()
function returns the data type of the argument passed to it. When the argument is an instance of a class, it returns the class that it is an instance of.
Syntax
type(some_object)
The type()
function primarily accepts some_object
as a parameter, which can be any of Python’s data types.
Example
The type()
function can be used to confirm the data type of the object spam
:
spam = 10print(type(spam))# Output: int
Codebyte Example
The following example uses the type()
function to return the data type of the class instance variable, home
:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours