Operator Overloading: sub : Operator Overloading « Class « Python Tutorial






class Number:
    def __init__(self, start):                
        self.data = start
    def __sub__(self, other):                 
        return Number(self.data - other)      

X = Number(5)                             
Y = X - 2                                 
print Y.data








11.5.Operator Overloading
11.5.1.Operator Overloading: add, sub, mul, div
11.5.2.Operator Overloading: sub
11.5.3.Classes Can Intercept Python Operators