Describing Object Behavior
-
In Python, everything is an object:
- Integers are objects
- Strings are objects
- Lists are objects
- Etc.
-
Objects are generally classified according to:
- Their behavior
- The features that they implement
- Notice, there is overlap between these two properties
-
For example, these objects have similar behavior:
- Strings
- Lists
- Tuples
- Xrange
- These objects are called sequence types
- Specifically, each sequence type is grouped together only because they support a common set of sequence operations
- For example, we can call and on sequence types
Introducing Special Methods
- All basic interpreter operations are implemented using special object methods
- These special methods always are preceded and followed by two underscores ( __ )
- These methods are automatically triggered by the interpreter during program execution
- The following examples are operations that map to internal methods:
- Evidently, the behavior of each data type depends entirely on the set of special methods that it implements
References
Next