Dividing A Timedelta

Overview:

  • A timedelta can be divided by an integer, a floating point value or by another timedelta.

Example:

# Example Python program that calculates 
# the mean CPU time for three processes
# using the class timedelta 
from datetime import timedelta

# Process times
process1CPUTime = timedelta(seconds = 4.5)
process2CPUTime = timedelta(seconds = 3)
process3CPUTime = timedelta(seconds = 6)

# Compute the mean
meanCPUTime = (process1CPUTime + process2CPUTime + process3CPUTime)/3
print("Mean CPU Time:")
print(meanCPUTime)

Output:

Mean CPU Time:

0:00:04.500000

 


Copyright 2023 © pythontic.com