InitCreates

Misconception:

The method __init__ must create a new object.

Incorrect

__init__ must create a new object

Correct

__init__ does not create the object, it just initializes it

Correction
Here is what's right.

The __init__ method does not create an object, it only initializes the attributes of the object. The object is created before __init__ is called. __init__ is just a method that can be used to add attributes immediately after the object is already created.

Read through Python’s tutorial on Class Objects to learn more.

Value
How can you build on this misconception?

This misconception is a great opportunity to discuss allocation / object creation versus attribute initialization. In Python, an object is created before its __init__ method is called. The __init__ method then customizes the object with an initial state, i.e., it sets the values of attributes of that object.

Opportunity to Discover Related Issues

If students use C() inside the __init__ method of class C, you may discuss how this would recursively invoke the __init__ method. Have them try this out, and see how it leads to an infinite recursion (i.e., a stack overflow).

If students assign the result of the instantiation to self, then they also have the SelfAssignable misconception.

If students return the result of the instantiaion, then they also have the InitReturnsObject misconception.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.