×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python date weekday() Method with Example

Python date.weekday() Method: In this tutorial, we will learn about the weekday() method of date class in Python with its usage, syntax, and examples. By Hritika Rajput Last updated : April 22, 2023

Python date.weekday() Method

The date.weekday() method returns the day of the week as an integer, where Monday is 0 and Sunday is 6. It is an instance method.

Module

The following module is required to use weekday() method:

import datetime

Class

The following class is required to use weekday() method:

from datetime import date

Syntax

The following is the syntax of weekday() method:

weekday()

Parameter(s)

The following are the parameter(s):

  • None

Return Value

The return type of this method is a number which tells us what is the day of the week on that day.

Example of date weekday() Method in Python

## importing date class
from datetime import date

## Creating an instance
x = date.today()
d = x.weekday()
print("Today's weekday number is:", d)

x = date(2020, 10, 30)
d1 = x.weekday()
print("Weekday number on the date",x,"will be:",d1)
print()

## Since we know the number, 
## we can save them in a list and 
## print the day on that number
day =["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
print("Today's day is:",day[d])
print("Day on date", x," will be:", day[d1])

Output

Today's weekday number is: 2
Weekday number on the date 2020-10-30 will be: 4

Today's day is: Wednesday
Day on date 2020-10-30  will be: Friday

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.