The abstract data type (ADT) definitions throughout the text include some operations that are suppose to be implemented using a Python operator. Those methods are specified using an italicized font. The table below maps the various ADT operations to the corresponding Python operator method that is suppose to be used in the implementation.
ADT Operation
| How is it Used
| Python Operator Method
| What it Returns
|
absolute()
| abs(obj)
| __abs__(self)
| New object of the same type.
|
add( rhsObj )
| y = x + rhsObj)
| __add__( self, rhsObj )
| New object of the same type.
|
comparable(rhsObj)
| x == y , x < y ,
x <= y , x != y ,
x >= y , x > y
| __eq__( self, rhsObj )
__lt__( self, rhsObj )
__le__( self, rhsObj )
| true or false
|
contains( item )
| item in obj
| __contains__( self, item )
| true or false
|
divide( rhsObj )
| y = x / rhsObj
| __truediv__(self, rhsObj)
| New object of the same type.
|
equal( rhsObj )
| x == rhsObj
| __eq__( self, rhsObj )
| true or false
|
getitem( index )
| y = obj[index]
| __getitem__( self, index )
| An object from the container.
|
length()
| len(obj)
| __len__( self )
| An integer value.
|
multiply( rhsObj )
| y = x * rhsObj
| __mul__( self, rhsObj )
| New object of the same type.
|
negate()
| y = -x
| __neg__( self )
| New object of the same type.
|
setitem(index, value)
| x[index] = value
| __setitem__(self, index, value)
| Nothing.
|
subtract( rhsObj )
| y = x - rhsObj
| __sub__( self, rhsObj )
| New object of the same type.
|
toFloat()
| float(obj)
| __float__( self )
| Floating point value.
|
toInt()
| int(obj)
| __int__( self )
| An integer value.
|
toString()
| str(obj)
| __repr__( self )
| A string.
|