Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the difference between init__ and __init__ in python class?
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/q/11899959/1329187">Some things</a> do not work if I use <code>__init__</code> instead of <code>init__</code> in a class. I am just curious what the difference between these two is.</p> <p>Here is a piece of the class. But it really does not matter because it works with <code>init__</code> and it doesn't with <code>__init__</code>. I understand that it was a typing error, then it means that I can actually call it any way.</p> <pre><code>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!') </code></pre> <p>My question there was "How to instantiate an object in two different ways?" and this way it works perfectly.</p> <p>How to explain this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload