Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Call-an-object-method/Python/call-an-object-method.py
Normal file
24
Task/Call-an-object-method/Python/call-an-object-method.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class MyClass(object):
|
||||
@classmethod
|
||||
def myClassMethod(self, x):
|
||||
pass
|
||||
@staticmethod
|
||||
def myStaticMethod(x):
|
||||
pass
|
||||
def myMethod(self, x):
|
||||
return 42 + x
|
||||
|
||||
myInstance = MyClass()
|
||||
|
||||
# Instance method
|
||||
myInstance.myMethod(someParameter)
|
||||
# A method can also be retrieved as an attribute from the class, and then explicitly called on an instance:
|
||||
MyClass.myMethod(myInstance, someParameter)
|
||||
|
||||
|
||||
# Class or static methods
|
||||
MyClass.myClassMethod(someParameter)
|
||||
MyClass.myStaticMethod(someParameter)
|
||||
# You can also call class or static methods on an instance, which will simply call it on the instance's class
|
||||
myInstance.myClassMethod(someParameter)
|
||||
myInstance.myStaticMethod(someParameter)
|
||||
Loading…
Add table
Add a link
Reference in a new issue