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 lessonWhat 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
- Create and Display a DateBeginner
- Calculate Days Between DatesBeginner
- Add Two Weeks to a DateIntermediate
- Parse a Date StringIntermediate
- Sort Events by DateAdvanced
All Python exercises · 50 practice problems · Standard Library Essentials quiz