Skip to content

Instantly share code, notes, and snippets.

@ivyleavedtoadflax
Created July 25, 2017 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivyleavedtoadflax/7056eebc66fcf4c77c490eea9789119d to your computer and use it in GitHub Desktop.
Save ivyleavedtoadflax/7056eebc66fcf4c77c490eea9789119d to your computer and use it in GitHub Desktop.
Different types of python method
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