SyntaxStudy
Sign Up
Home Python Reference type() / isinstance()

type() / isinstance()

function

type() returns the type of an object; isinstance() checks if an object is an instance of a class.

Syntax

type(object) isinstance(object, classinfo)

Example

python
print(type(42))         # <class 'int'>
print(type('hello'))    # <class 'str'>
print(type([1,2,3]))    # <class 'list'>

print(isinstance(42, int))        # True
print(isinstance('hi', str))      # True
print(isinstance(42, (int,float))) # True