type()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
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 = 10
print(type(spam))
# Output: int

Codebyte Example

The following example uses the type() function to return the data type of the class instance variable, home:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy