Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. class Date(object):
  2.     # Note: doesn't return, or print, anything, just initializes self.
  3.     # Also notice that this, and all other methods, takes self as a
  4.     # parameter. Also notice the way you set default values.
  5.     def __init__(self, year=1900, month=1, day=1):
  6.         self.year, self.month, self.day = year, month, day
  7.  
  8.     # Here's where you define what it looks like if someone just types
  9.     # date_one at the interactive prompt.
  10.     def __repr__(self):
  11.         return '{} {}, {}'.format(month_names[self.month], self.day, self.year)
  12.  
  13.     # Here's where you define what it looks like when someone calls str()
  14.     # or print() on your instances.
  15.     def __str__(self):
  16.         return '{:04}-{:02}-{:02}'.format(self.year, self.month, self.day)
  17.  
  18.     # Notice that this takes an other argument, not separate year,
  19.     # month, and day.
  20.     def same_date_in_year(self, other):
  21.         return (self.month, self.day) == (other.month, other.day)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement