Home »
Python »
Python Reference »
Python calendar Module
Python calendar setfirstweekday() Method with Example
Python calendar.setfirstweekday() Method: In this tutorial, we will learn about the setfirstweekday() method of calendar module in Python with its usage, syntax, and examples.
By Hritika Rajput Last updated : April 24, 2023
Python calendar.setfirstweekday() Method
The calendar.setfirstweekday() method is an inbuilt method of the calendar module, it is used to set the first weekday from when the week should start. Here, Monday is 0, incrementing by 1 till Sunday, which is 6. We can also use calendar.day_name where calendar.MONDAY is 0 and calendar.SUNDAY is 6.
Module
The following module is required to use setfirstweekday() method:
import calendar
Syntax
The following is the syntax of setfirstweekday() method:
setfirstweekday(weekday)
Parameter(s)
The following are the parameter(s):
- weekday: It is an optional parameter, which represents the weekday number where MONDAY is 0 and SUNDAY is 6. Its default value is 0.
Return Value
The return type of this method is <class 'NoneType'>, it sets an iterator for the week day numbers.
Example of calendar.setfirstweekday() Method in Python
# Python program to illustrate the
# use of setfirstweekday() method
# importing calendar module
import calendar
# using setfirstweekday() function
val = calendar.setfirstweekday(2)
# returns None
print(val)
# The function does not return anything,
# it only sets the value
print()
val = calendar.setfirstweekday(calendar.WEDNESDAY)
# sets the value to 2 which is the weekday value
# for WEDNESDAY
print(val)
print()
# Using firstweekday() method to check what was
# the day sets
calendar.setfirstweekday(calendar.SUNDAY)
print(calendar.firstweekday())
# Prints 6 which is the weekday value for SUNDAY
Output
None
None
6