What is a data type timedelta good for in Python?

Experience Level: Junior
Tags: Python

Answer

This data type represent the difference between two datetime objects.

 Supported operators:

  • add, subtract timedelta
  • unary plus, minus, abs
  • compare to timedelta
  • multiply, divide by int

In addition, datetime supports subtraction of two datetime objects returning a timedelta, and addition or subtraction of a datetime and a timedelta giving a datetime.

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself