Class Method

Class Method គឺ​ជា​ method ទាំងឡាយ​ណា​ ដែល​ត្រូវការ​ថ្នាក់​សំរាប់ patameter ទី​មួយ​នៅ​ក្នុង method នោះ​។ ពិនិត្យ​កម្មវិធី​ខាង​ក្រោម​នេះ៖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Cash():
    def __init__(self):
        print('The constructor has been called.')
 
    def display(cl):
        print(cl)
 
    display = classmethod(display)
 
 
money = Cash()
 
Cash.display()
money.display()
1
2
3
The constructor has been called.
<class '__main__.Cash'>
<class '__main__.Cash'>

ជារួម ការ call class method បណ្តាល​អោយ​ថ្នាក់​មួយ​ត្រូវ​ផ្តល់​ជា argument អោយ​ method នោះ​ជា​ស្វ័យប្រវត្តិ ទោះ​ចង់​ក្តី​មិន​ចង់​ក្តី​៕