Some things do not work if I use __init__
instead of init__
in a class. I am just curious what the difference between these two is.
Here is a piece of the class. But it really does not matter because it works with init__
and it doesn't with __init__
. I understand that it was a typing error, then it means that I can actually call it any way.
class Point(namedtuple('Point', 'x, y, z')):
'class of a point as a tuple array'
__slots__ = () # prevent creation of instance dictionaries to save memory
def init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __del__(self):
'delete the Point'
def __repr__(self):
'Return a nicely formatted representation string'
return '[%r, %r, %r]' % (self)
def __str__(self):
'printing format'
return '%s[%r, %r, %r]' % (self.__class__.__name__,
self.x, self.y, self.z)
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y, self.z + other.z)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y, self.z - other.z)
def __mul__(self, scal):
'multiplication ny scalar'
return Point(self.x * scal, self.y * scal, self.z * scal)
def __div__(self, scal):
'division ny scalar'
if scal != 0.0:
return Point(self.x / scal, self.y / scal, self.z / scal)
else:
sys.exit('Division by zero!')
My question there was "How to instantiate an object in two different ways?" and this way it works perfectly.
How to explain this?