More Built-in Types

Python does not ship with only two objects. Oh no, the two primitives come with a whole gang of buddies.

Figure 2.2. Some Built-in Types

Some Built-in Types

A few built-in types are shown above, and examined below.

Example 2.3. Examining some built-in types

>>> list 1
<type 'list'>
>>> list.__class__  2
<type 'type'>
>>> list.__bases__  3
(<type 'object'>,)
>>> tuple.__class__, tuple.__bases__ 4
(<type 'type'>, (<type 'object'>,))
>>> dict.__class__, dict.__bases__ 5
(<type 'type'>, (<type 'object'>,))
>>>
>>> mylist = [1,2,3] 6
>>> mylist.__class__ 7
<type 'list'>



1

The built-in <type 'list'> object.

2

Its type is <type 'type'>.

3

It has one base (a.k.a. superclass), <type 'object'>.

4 5

Ditto for <type 'tuple'> and <type 'dict'>.

6

This is how you create an instance of <type 'list'>.

7

The type of a list is <type 'list>. No surprises here.

When we create a tuple or a dictionary, they are instances of the respective types.

So how can we create an instance of mylist? We cannot. This is because mylist is a not a type.