How to make a class which could operate like this without importing other modules?
>>date(2014,2,2) + delta(month=3)
>>(2014, 5, 2)
>>
>>date(2014, 2, 2) + delta(day=3)
>>(2014, 2, 5)
>>date(2014, 2, 2) + delta(year=1, month=2)
>>(2015, 4, 2)
This is my code:
# class delta(date):
# year = date(year)
# def __init__(self,y,m,d):
# self.y = y + year
# self.m = m
# self.d = d
# def __call__(self):
# return self.y, self.m, self.d
class date(object):
def __init__(self,year,month,day):
self.year = year
self.month = month
self.day = day
def __call__(self):
return self.year, self.month, self.day
deltahave to be its own class, could you just make adeltafunction indateclass?__add__and__iadd__.