what is the error of this code

Asked

Viewed 56 times

0

class Point3D(object):
    def _init_(self,x,y,z):
     a=str(x) 
     self.x=a
     a=str
     self.y=a
     a=a+","
     a=str(z)
     self.z=a
    def _repr_(self):
        return "(%d,%d,%d)"%(self.x,self.y,self.z)

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

    Hello, Emanuel. Welcome. Your question is very confusing. It’s hard to tell what the mistake is without knowing what you’re up to and what’s going on instead. If there is any compiler/interpreter error output, it is also important that you do. If you haven’t already, how about doing a [tour] of the site to better understand how it works? Then go back and edit your question by clicking on the "Edit] link".

1 answer

2

Study the coemnet done, and try to improve the issue - but looking at the code, even without knowing the message you see, one wrong thing is that the method _init_ should be __init__ (with two underscores prefix and suffix) - to have the effect you probably intend: that is, that it is automatically called by the language when the class Point3D is instantiated.

It is a convention of language, all the methods that will be called by internal mechanisms of language are surrounded by two sublinahdos __ on either side.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.