1
Contents
Tips, Tricks, and Pitfalls ………………………………………………………………………………………………………………………………………. 1
Level 5 …………………………………………………………………………………………………………………………………………………………… 1
I: Dates and Times ………………………………………………………………………………………………………………………………………. 1
II: Decorators ……………………………………………………………………………………………………………………………………………… 2
Tips, Tricks, and Pitfalls
Level 5
I: Dates and Times
1. While this is not directly related to datetime, the operator module can come in handy when dealing with
timedelta objects (and in many other situations). The operator module contains some useful functions that can
be used instead of the standard Python operators. For example, operator.add is equivalent to + and
operator.sub is equivalent to -. This can be useful if you wish to use an operator as a callable (to store in a
variable or pass around as parameters to other functions). One such example is below:
Hint: This may come in handy for one of the exercises.
2
II: Decorators
1. The lecture mentioned that decorators are syntactic sugar and demonstrates how to create a simple decorator.
However, we glossed over what the alternative (non syntactic-sugar) approach would be to achieve the same
thing. The below is an example of function wrapping, with and without decorators:
Without decorators:
With decorators: