TypeError:Point() takes no arguments

I don’t know why I have a TypeError here. I followed my instructor’s code, he successfully got the answer, but i can’t. Does anyone help?

class Point:
def init(self, x, y):
self.x = x
self.y = y

def draw(self):
    print(f"Point({self.x}, {self.y})")

point = Point(1, 2)
print.draw()

the result is below:
Traceback (most recent call last):
File “/Users/lichangtan/Desktop/gracetan/app.py”, line 28, in
point = Point(1, 2)
TypeError: Point() takes no arguments

You have only a single underscore at the beginning and end of the
init method. It should be

__init__  # double leading and trailing underscores
_init_  # you have only single underscores

In general, all “special” methods in Python classes will have double
leading and trailing underscores. We even have a name for this:
“dunder” methods (Double leading and trailing UNDERscore methods).

5 Likes