python-CSD-kursu/python-temel/staticmethod.2.py

23 lines
822 B
Python
Raw Permalink 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 Date:
def __init__(self, day, month, year):
self.day = day
self.month = month
self.year = year
def disp(self):
print('{}/{}/{}'.format(self.day, self.month, self.year))
@staticmethod
def isLeapYear(year):
return year % 400 == 0 or year % 4 == 0 and year % 100 != 0
date = Date(10, 12, 2007)
date.disp() # örnek metodun çağrılması için asıl biçim
Date.disp(date) # örnek metodun çağrılması için alternatif biçim
result = Date.isLeapYear(2000) # static metodun çağrılması için asıl biçim
print('Artık' if result else 'Artık değil')
result = date.isLeapYear(2000) # static metodun çağrılması için alternatif biçim
print('Artık' if result else 'Artık değil')