staticmethod example 3

This commit is contained in:
Mert Gör 🇹🇷 2023-08-03 23:29:39 +03:00
parent bef5decfb9
commit f6d3145a2e
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,12 @@
class Sample:
def foo(self):
print('foo')
@staticmethod
def bar(self):
print('bar')
s = Sample()
s.foo() # Sample.foo(s)
s.bar(10) # geçerli, 10 burada self'e atanacak
#s.bar() # exception, çünkü self sıradan bir parametre

View File

@ -0,0 +1,15 @@
class Sample:
def foo(self):
print('foo')
@staticmethod
def bar(self):
print('bar')
s = Sample()
s.foo()
# Sample.foo(s)
s.bar(10)
# geçerli, 10 burada self'e atanacak
s.bar()
# exception, çünkü self sıradan bir parametre