Python - Constructors method __init__

Introduction

The following class Number implement two methods: constructor and subtraction.

Demo

class Number: 
    def __init__(self, start):                  # On Number(start) 
        self.data = start # from   w  w  w  .j  ava  2 s.  c  o m
    def __sub__(self, other):                   # On instance - other 
        return Number(self.data - other)        # Result is a new instance 

X = Number(5)                               # Number.__init__(X, 5) 
Y = X - 2                                   # Number.__sub__(X, 2) 
print( Y.data )                             # Y is new Number instance

Result