Building useful classes


Below is my code:

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

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

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

it gives me below error:

(1, 2, 3)
Traceback (most recent call last):
File "python", line 11, in
TypeError: str returned non-string (type NoneType)

whats does this error means can anyone please explain me?



The __repr__() method should return the string, instead of printing it.


Can you please tell me whats wrong in my code it gives me continuous this error?


Did you try to change the print by a return? If yes, could you give the updated code in a formatted version?


Ok thanks, it worked