Is a date a weekend?

EasyDatetime Programs · 8 of 20

Write a Python program to check whether dates fall on a weekend.

Advertisement
Output
2026-10-31 weekend
2026-11-02 weekday

Approach

  1. weekday() is 5 or 6 for Saturday and Sunday.

Solution

Python
from datetime import date for d in [date(2026, 10, 31), date(2026, 11, 2)]:    print(d, "weekend" if d.weekday() >= 5 else "weekday")
Output
2026-10-31 weekend
2026-11-02 weekday

Learn the concept

New to this topic? Read the lesson, then come back.

More datetime programs

← All 20 Datetime Programs

Leave a Comment