Created
July 25, 2017 23:50
-
-
Save ivyleavedtoadflax/7056eebc66fcf4c77c490eea9789119d to your computer and use it in GitHub Desktop.
Different types of python method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Date(object): | |
def __init__(self, day=0, month=0, year=0): | |
self.day = day | |
self.month = month | |
self.year = year | |
def print(self): | |
return self.day, self.month, self.year | |
@classmethod | |
def from_string(cls, date_as_string): | |
day, month, year = map(int, date_as_string.split('-')) | |
date1 = cls(day, month, year) | |
return date1 | |
@staticmethod | |
def is_date_valid(date_as_string): | |
day, month, year = map(int, date_as_string.split('-')) | |
return day <= 31 and month <= 12 and year <= 3999 | |
# usage: | |
is_date = Date.is_date_valid('11-09-2012') | |
date2 = Date.from_string('11-09-2012') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment