CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 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