class method 2
This commit is contained in:
parent
375b7cddd1
commit
50630be6f0
1 changed files with 25 additions and 0 deletions
25
python-temel/classmethod.2.py
Normal file
25
python-temel/classmethod.2.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
class Sample:
|
||||
def __init__(self): #örnek metodu
|
||||
self.a = 10
|
||||
|
||||
def foo(self): #örnek metodu
|
||||
print('foo')
|
||||
|
||||
@staticmethod
|
||||
def bar(): # statik metot
|
||||
print('bar')
|
||||
|
||||
@classmethod # sınıf metodu
|
||||
def tar(cls):
|
||||
print('tar')
|
||||
|
||||
|
||||
s = Sample()
|
||||
s.foo() # örnek foo metodu çağrılır
|
||||
|
||||
Sample.bar() # statik bar metodu
|
||||
Sample.tar() # Sınıf tar metodu, Sample cls pa
|
||||
|
||||
s.bar() # statik bar metodu
|
||||
s.tar() # sınıf tar metodu, Sample cls parametresi olarak geçirilir
|
||||
|
Loading…
Reference in a new issue