11.11 Building usefull classes. Is something wrong with Python?


#1

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?


#2

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.


#3

Hi Try to refresh the page.


#4

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


#5

it should class Point3D not def Point3D