python-CSD-kursu/python-temel/classmethod.2.py
2023-08-03 23:44:57 +03:00

26 lines
816 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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