Home »
Python »
Python Reference »
Python calendar Module
Python calendar firstweekday() Method with Example
Python calendar.firstweekday() Method: In this tutorial, we will learn about the firstweekday() method of calendar module in Python with its usage, syntax, and examples.
By Hritika Rajput Last updated : April 24, 2023
Python calendar.firstweekday() Method
The calendar.firstweekday() method is an inbuilt method of the calendar module, it returns the current setting for the weekday to start each week.
Module
The following module is required to use firstweekday() method:
import calendar
Syntax
The following is the syntax of firstweekday() method:
firstweekday()
Parameter(s)
The following are the parameter(s):
Return Value
The function returns a number from 0 to 6 where Monday indicates 0 and so on.
Example of calendar.firstweekday() Method in Python
# Python program to illustrate the
# use of firstweekday() method
# importing calendar module
import calendar
# using setfirstweekday() function
calendar.setfirstweekday(2)
print(calendar.firstweekday())
print()
val = calendar.setfirstweekday(calendar.FRIDAY)
# sets the value to 4 which is the weekday value for FRIDAY
print(calendar.firstweekday())
# prints 4
print()
# Printing 3rd month of 2020
calendar.setfirstweekday(calendar.THURSDAY)
print("Third month of 2020:")
calendar.prmonth(2020, 3, 2, 1)
# It starts displaying the calendar from THURSDAY
print("The first weekday of the third month of 2020 is:", calendar.firstweekday())
Output
2
4
Third month of 2020:
March 2020
Th Fr Sa Su Mo Tu We
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
The first weekday of the third month of 2020 i
s: 3