There are two kinds of objects in Python:
Type objects - can create instances, can be subtyped.
Non-type objects - cannot create instances, cannot be subtyped.
<type 'type'>and<type 'object'>are two primitive objects of the system.objectname.__class__exists for every object and points the type of the object.objectname.__bases__exists for every type object and points the supertypes of the object. It is empty only for<type 'object'>.To create a new object using subtyping, we use the
classstatement and specify the bases (and, optionally, the type) of the new object. This always creates a type object.To create a new object using instantiation, we use the call operator (
()) on the type object we want to use. This may create a type or a non-type object, depending on which type object was used.Some non-type objects can be created using special Python syntax. For example,
[1, 2, 3]creates an instance of<type 'list'>.Internally, Python always uses a type object to create a new object. The new object created is an instance of the type object used. Python determines the type object from a
classstatement by looking at the bases specified, and finding their types.issubtype(A,B)(testing for supertype-subtype relationship) returnsTrueiff:Bis inA.__bases__, orissubtype(Z,B)is true for anyZinA.__bases__.
isinstance(A,B)(testing for type-instance relationship) returnsTrueiff:BisA.__class__, orissubtype(A.__class__,B)is true.
Squasher is really a python. (Okay, that wasn't mentioned before, but now you know.)