class method 2

This commit is contained in:
Mert Gör 🇹🇷 2023-08-03 23:44:57 +03:00
parent 375b7cddd1
commit 50630be6f0
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9

View 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