Python weekday(): Get Day of Week Index

In Python, the weekday() function is used to retrieve the index value of the day of the week for a given date, with the return value ranging from 0 to 6, where 0 represents Monday, 1 represents Tuesday, and so on, with 6 representing Sunday.

Here is an example using the weekday() function:

import datetime

date = datetime.date(2022, 10, 31)
weekday_index = date.weekday()

print("Weekday index:", weekday_index)

The output results in:

Weekday index: 0

This indicates that October 31, 2022 falls on a Monday.

bannerAds