python datetime add

add_time = datetime.timedelta(days=2)

Here is what the above code is Doing:
1. We’re creating a new class, called Timedelta.
2. We’re setting the __init__ method to take two parameters: self and days.
3. We’re setting the __add__ method to take two parameters: self and other.
4. We’re creating a new instance of Timedelta, called add_time, and setting it to datetime.timedelta(days=2).

The __init__ method is called when you create a new instance of a class. The __add__ method is called when you use the + operator on two instances of a class. In this case, we’re adding two Timedelta instances together.

We can use our new class like this:

>>> print(add_time)
2 days, 0:00:00
>>> print(add_time + datetime.timedelta(days=1))
3 days, 0:00:00
>>> print(add_time + datetime.timedelta(days=2))
4 days, 0:00:00

As you can see, our new class behaves just like the datetime.timedelta class.