I’m confused in bellowing code:
class Point():
def __init__(self, x=0, y=0):
self.x = x
self.y = y
I do not understand what those two x in code self.x = x mean.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
self.xis an attribute of the Point class. So if p is an instance of the Point class, thenp.xis theself.xyou see above (self being a reference to the class you are defining). The secondxis the parameter passed at init timedef __init__(self, x=0, y=0):. Note that it defaults to zero in case you don’t pass anything.