type(object)

type(name, bases, dict, **kwds)

Returns the type of an object.

Parameters

The type() function takes either a single parameter object or three parameters:

  • name - class name; becomes the __name__ attribute
  • bases - tuple listing base classes; becomes the __bases__ attribute
  • dict - dictionary representing the namespace with class body definitions; becomes the __dict__ attribute

Return Value

The type() function returns:

  • the type of the object if only one parameter is passed
  • a new type if three parameters are passed

Examples

numbers_list = [1, 2]
print(type(numbers_list))

numbers_dict = {1: 'one', 2: 'two'}
print(type(numbers_dict))


class Foo:
    a = 0

foo = Foo()
print(type(foo))

# Output

<class 'list'>
<class 'dict'>
<class '__main__.Foo'>