Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is date.isoweekday() in python?

Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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 the date class in Python.

Syntax


date.isoweekday()

Parameters

This method doesn’t take any argument value(s).

Return value

weekday: This method returns the day of a week as an integer value (1–7).

Weekday Number

Integer Value

Day of the week

1

Monday

2

Tuesday

3

Wednesday

4

Thursday

5

Friday

6

Saturday

7

Sunday

Code example

The following code snippet elaborates on how we can use the isoweekday() method in a program:

# importing the date class from datetime
from datetime import date
# To show readbale results let's define
# Dictionay with days labeled
# From 1 to 7
weekdays= { 1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
7: "Sunday"}
# Getting today's date
todays_date = date.today()
print("Today's date:", todays_date)
# Using the isoweekday() function
# From date class
dayNumber = todays_date.isoweekday()
# Print results on console
print("Date:", todays_date, "falls on", weekdays[dayNumber])

Code explanation

  • Line 2: We import the date class from the datetime module.
  • Line 6: We create a dictionary to show the weekdays.
  • Line 15: We extract today’s date.
  • Line 20: We get the weekday in the dayNumber variable, using the isoweekday() method.
  • Line 22: We print the results on the console with a mapped weekday.

RELATED TAGS

python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring