Building useful classes


#1



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?
`


#2

Hi

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


#3

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


#4

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


#5

Ok thanks, it worked