Can this code
class Point:
def __init__(self,x,y):
self.x=x
self.y=y
def __str__(self):
return "Point({},{})".format(self.x,self.y)
p=Point(3,5)
print(p)
be modified to following code?
class Point:
def __init__(p,x,y):
p.x=x
p.y=y
def __str__(p):
return "Point({},{})".format(p.x, p.y)
p=Point(3,5)
print(p)
It seems to be worked in this case. But it is so naive case. I wonder using other than 'self' will cause some problem in some situations.
The first argument is the reference to the bound variable or object. Its convention to use self but anything else will also work. check the doc here.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments