Pretty Print Time Difference in Python

First, to measure time, you can use:

import time
import datetime

start = time.perf_counter()
# ... some work ...
end = time.perf_counter()

duration = end - start

To pretty print time, use the following:


which displays something like 1:14:13 (hours:minutes:seconds).

To contact me, send an email anytime or leave a comment below.