Dividing a timedelta

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

Timedelta Updated 7 Aug 2021 1 min read

Overview

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

Example

python
# 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

Output
Mean CPU Time:

0:00:04.500000