Python calendar module | firstweekday() 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.firstweekday() is a function provided in calendar module for simple text calendars.
firstweekday() method is used to get the current setting for the weekday to start each week.
Syntax: firstweekday() Parameter: no parameter Returns: None
Code #1:
# Python program to explain working of firstweekday() method # importing calendar module import calendar # default firstweekday print("Default First weekday is - ", calendar.firstweekday()) # setting 2nd day as firstweekday calendar.setfirstweekday(2) # print firstweekday print("First weekday after modification is - ", calendar.firstweekday()) |
Output:
Default First weekday is - 6 First weekday after modification is - 2
Code #2: Explaining working of firstweekday() method with prmonth() method
# Python code to demonstrate the working of # firstweekday() with help of 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("First weekday after modification is - ", calendar.firstweekday()) |
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
First weekday after modification is - 4
Recommended Posts:
- Python calendar module | leapdays() method
- Python calendar module | itermonthdays2() method
- Python calendar module | formatmonth() method
- Python calendar module | itermonthdays() method
- Python calendar module | monthdatescalendar() method
- Python calendar module | isleap() method
- Python calendar module | prmonth() method
- Python calendar module | formatyear() method
- Python calendar module | setfirstweekday() method
- Python calendar module | pryear() method
- Python calendar module | monthdays2calendar() method
- Python calendar module | monthdayscalendar() method
- Python calendar module | yeardatescalendar() method
- Python calendar module | yeardayscalendar() method
- Python calendar module | yeardays2calendar() method
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.



