datetime.timedelta
can be used to represent the difference between two dates. In order to create a class variable representing delta from day to day, we can create a staticmethod
that takes two dates as input and returns a timedelta
representing the difference between them.
Here's an example:
main.py350 chars16 lines
In this example, MyClass
has a staticmethod
called days_delta
, which takes two datetime.date
objects as arguments. The days_delta
method returns the number of days between the two dates as an integer.
You can then call the days_delta
method without needing to create instance of the class.
Note that in the above example the date class is from datetime module.
gistlibby LogSnag