Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Date(object):
- # Note: doesn't return, or print, anything, just initializes self.
- # Also notice that this, and all other methods, takes self as a
- # parameter. Also notice the way you set default values.
- def __init__(self, year=1900, month=1, day=1):
- self.year, self.month, self.day = year, month, day
- # Here's where you define what it looks like if someone just types
- # date_one at the interactive prompt.
- def __repr__(self):
- return '{} {}, {}'.format(month_names[self.month], self.day, self.year)
- # Here's where you define what it looks like when someone calls str()
- # or print() on your instances.
- def __str__(self):
- return '{:04}-{:02}-{:02}'.format(self.year, self.month, self.day)
- # Notice that this takes an other argument, not separate year,
- # month, and day.
- def same_date_in_year(self, other):
- return (self.month, self.day) == (other.month, other.day)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement