11.11 Building usefull classes. Is something wrong with Python?


def Point3D(object):
def init(self, x, y, z):
self.x = x
self.y = y
self.z = z

def __repr__(self):
    return "(%d, %d, %d)" % (self.x, self.y, self.z)

my_point = Point3D(1, 2, 3)
print my_point

For some reason, even with this being the correct code, based on my friend who has recently completed this lesson, as well as the rest of the Q and A, I receive this error:

Traceback (most recent call last):
File "python", line 10, in
TypeError: Point3D() takes exactly 1 argument (3 given)

Would someone please explain to me what is going on?


Obviously your friend should refresh his python knowledge.

If you want to define a class you should use a class keyword. And it should be __init__, not init.

Because you have used def keyword python thinks that you want to create a function that takes one parameter - object. This is why you are getting this error.


Hi Try to refresh the page.


useful has one l(I need at lleast twenty characters to post this)


it should class Point3D not def Point3D