I am new to Python, so please don't cry if I ask for something too noobish :)
1.
I have a class:
class Test:
def __init__(self, x, y):
self.x = x
self.y = y
def wow():
print 5 * 5
Now I am trying to create a class object:
x = Test(3, 4)
This works as expected. However, when I try to call the wow () method, it returns an error, which is fixed by changing wow () to:
def wow(self)
Why do I need to enable self, and if not, what does this method mean?
2. In the definition __init__:
def __init__(self, x, y):
self.x = x
self.y = y
Why do I need to declare x and y when I can do this:
def __init__(self):
self.x = x
self.y = y
I hope I clear up ...
Thank you for your time.
source
share