11. Building Useful Classes


#1

Can anyone tell me the issue with my code, I am getting an indentation error for the def__repr__() method
class 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


#3
class 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

#4

look at the indention:

bit too much indent, which is why you get an error


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.