Skip to the content

Dates

Python · Unit 16: The standard library

date holds a date: year, month and day, in that order. It lives in the datetime module.

There is a date.today() that gives today's date, but here we always use fixed dates: that way the lesson reads the same today and a year from now.

from datetime import date

d = date(2026, 9, 22)
print(d)

Prints

2026-09-22

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Complete the code

    Complete it to build the date. It should print: 2026-01-05

  3. 3. Predict the output

    What does this code print?

  4. 4. Predict the output

    What does this code print?

  5. 5. Predict the output

    How many days are there from January 1st to March 1st, 2026?

  6. 6. Find the bug

    It should print only the number of days between the two dates. Which line has the error?

  7. 7. Complete the code

    Complete it so it prints: 22/09/2026

  8. 8. Predict the output

    What does this code print?

  9. 9. Multiple choice

    What happens when you run date(2026, 2, 30)?

  10. 10. Put the lines in order

    Put the lines in order to build delivery(days), the delivery date counting from September 22nd, 2026.

  11. 11. Find the case that fails

    days_left(month, day) returns how many days are left from September 22nd, 2026 to that date of the same year, and 0 if that date has already passed. Which call breaks it?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →