Question 9
Back to Exercise
What is the output of the following Python program?
from datetime import date, timedelta
d = date(2026, 12, 30) + timedelta(days=5)
print(d, d.strftime("%d %b %Y"), d.weekday(), (d - date(2026, 1, 1)).days)
- A 2026-12-35 35 Dec 2026 0 368
- B 2027-01-04 04 Jan 2027 0 368 Correct
- C 2027-01-04 04 Jan 2027 1 369
- D 2027-01-04 4 January 2027 0 368
Correct Answer: Option B
timedelta rolls over the month and year. weekday() is 0 for Monday. 4 January 2027 is 368 days after 1 January 2026.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!