×

python · level 2 · unit 5 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A holds a day, and subtracting dates counts the days.

imports two things by name, so you can write date instead of datetime.date. date(2026, 12, 25) is Christmas Day 2026: year, month, then day.

Subtract one date from another and you get a , a length of time. Its .days says how many days apart they are. Add timedelta(days=7) to a date and you land a week later.

turns a date into text: %d is the day, %m the month number, %B the month name, %Y the year and %A the weekday.

from datetime import date, timedelta
today = date(2026, 11, 2)
christmas = date(2026, 12, 25)
wait = christmas - today
print(f"{wait.days} days to go")
print(today + timedelta(days=7))
print(christmas.strftime("%A %d %B %Y"))

Lessons use fixed dates, because date.today() gives a different answer every day.