Adding two timedelta instances

Overview:

  • Through addition, two or more time durations from timedelta instances can be added to obtain the total time duration. For example, time durations taken by two or more tasks are summed together to get the total time taken.

Example:

# Example Python program that adds multiple
# time durations specified by the datetime.timedelta
# instances
from datetime import timedelta

t1Player1Relay = timedelta(seconds = 12)
t1Player2Relay = timedelta(seconds = 14)
t1Player3Relay = timedelta(seconds = 16)
t1Player4Relay = timedelta(seconds = 16)

t1TotalTime = t1Player1Relay + t1Player2Relay + t1Player3Relay + t1Player4Relay

print("Team1 total relay race time:")
print(t1TotalTime)   

Output:

Team1 total relay race time:

0:00:58


Copyright 2024 © pythontic.com