This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Dates and Times with datetime, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
What does date(2026, 1, 1).isoformat() return?
Answer: 2026-01-01
Why: isoformat uses the sortable YYYY-MM-DD representation.
What does adding a timedelta to a date return?
Answer: A new date object
Why: Date objects are immutable, so addition returns a new date.
How do you get the number of days in a timedelta?
Answer: delta.days
Why: days is an attribute, not a method.
Which strftime pattern gives a four-digit year?
Answer: %Y
Why: %Y is the four-digit year; %y is two digits.
Complete the method that returns YYYY-MM-DD.
from datetime import date
print(date(2026, 1, 1).____())Answer: isoformat
Why: isoformat returns the standard ISO date string.
Complete the duration class.
from datetime import date, timedelta
print(date(2026, 1, 1) + ____(days=2))Answer: timedelta
Why: timedelta represents a difference between dates or times.
Complete the attribute that gives the day count.
from datetime import date
print((date(2026, 1, 3) - date(2026, 1, 1)).____)Answer: days
Why: Subtracting dates returns a timedelta with a days attribute.
Complete the format pattern for a four-digit year.
from datetime import date
print(date(2026, 10, 27).strftime("____/%m/%d"))Answer: %Y
Why: A percent sign and capital Y represent the year.
What is the output?
from datetime import date
print(date(2026, 1, 2).isoformat())Answer: 2026-01-02
Why: isoformat returns the date as YYYY-MM-DD.
What does this code print?
from datetime import date
print((date(2026, 1, 3) - date(2026, 1, 1)).days)Answer: 2
Why: The difference is two days.
What does the program output?
from datetime import date, timedelta
print((date(2026, 1, 1) + timedelta(days=1)).isoformat())Answer: 2026-01-02
Why: Adding one day moves the date to January 2.
What appears on the screen?
from datetime import date
print(date(2026, 12, 31).strftime("%Y/%m/%d"))Answer: 2026/12/31
Why: The numeric pattern produces year, month, and day separated by slashes.
Try the questions first
Open the practice page for Python Dates and Times with datetime and answer the same 12 questions with instant feedback.