Python calendar module | setfirstweekday() method

Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions.

In Python, calendar.setfirstweekday(weekday) is a function provided in calendar module for simple text calendars.

setfirstweekday() method sets the weekday (0 is Monday, 6 is Sunday) to start each week. The values MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, and SUNDAY are provided for convenience.
For example, to set the first weekday to Sunday.



Syntax: setfirstweekday()
Parameter: no parameter
Returns: None

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to explain working of setfirstweekday() method
  
# importing calendar module
import calendar
  
# calling setfirstweekday() function
val = calendar.setfirstweekday(calendar.SUNDAY)
  
# returns None
print(val)

chevron_right


Output:

None

 
Code #2: Explaining working of setfirstweekday() method with prmonth() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to demonstrate the working of 
# setfirstweekday() with prmonth() method
  
# importing calendar module for calendar operations 
import calendar 
  
# using prmonth() to print calendar of 1997 
print ("The 4th month of 1997 is : "
calendar.prmonth(1997, 4, 2, 1
  
  
# using setfirstweekday() to set first week day number 
calendar.setfirstweekday(4
  
print ("\r"
  
# using firstweekday() to check the changed day 
print ("The new week day number is : ", end ="") 
print (calendar.firstweekday()) 

chevron_right


Output:

The 4th month of 1997 is : 
     April 1997
Mo Tu We Th Fr Sa Su
    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
 
The new week day number is : 4


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.