What is the output of the following Python code snippet?
from datetime import date
print((date(2024, 1, 8) - date(2024, 1, 1)).days)
print((date(2024, 1, 8) - date(2024, 1, 1)).days)
Correct answer
D. 7
6 views
D. 7
6 views
Subtracting two dates gives a timedelta whose days attribute holds the difference.
Asked in: Python Interview Standard Library
https://docs.python.org/3/library/index.htmlNot sure why the answer is D? Ask here and get an explanation.