Editor

Predict the Date Output

Intermediate · Predict the output · from Python datetime: Dates, Times, Timezones, and Calculations

From the lesson: Python datetime: Dates, Times, Timezones, and Calculations

Think about your phone. It shows the current time, tracks your calendar events, and reminds you about birthdays. Behind the scenes, all of that runs on date and time calculations.

Read the lesson

What does this code print? Think carefully about date arithmetic.

from datetime import date, timedelta
d = date(2024, 2, 28)
result = d + timedelta(days=1)
print(result)
from datetime import date, timedelta
d = date(2024, 2, 28)
result = d + timedelta(days=1)
print(result)

More datetime exercises

All Python exercises · 50 practice problems · Standard Library Essentials quiz