This isoweekday()
method returns an integer value that corresponds to the weekday. It returns 1
for Monday, 2
for Tuesday, and so on.
Note: The
isoweekday()
method comes from thedate
class in Python.
date.isoweekday()
This method doesn’t take any argument value(s).
weekday
: This method returns the day of a week as an integer value (1–7).
Integer Value | Day of the week |
| Monday |
| Tuesday |
| Wednesday |
| Thursday |
| Friday |
| Saturday |
| Sunday |
The following code snippet elaborates on how we can use the isoweekday()
method in a program:
# importing the date class from datetimefrom datetime import date# To show readbale results let's define# Dictionay with days labeled# From 1 to 7weekdays= { 1: "Monday",2: "Tuesday",3: "Wednesday",4: "Thursday",5: "Friday",6: "Saturday",7: "Sunday"}# Getting today's datetodays_date = date.today()print("Today's date:", todays_date)# Using the isoweekday() function# From date classdayNumber = todays_date.isoweekday()# Print results on consoleprint("Date:", todays_date, "falls on", weekdays[dayNumber])
date
class from the datetime
module.dayNumber
variable, using the isoweekday()
method.