ADVERTISEMENT
ADVERTISEMENT

Python calendar Module | firstweekday() Method with Example

Python calendar.firstweekday() Method: Here, we are going to learn about the firstweekday() method of calendar module in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on May 07, 2020

Python calendar.firstweekday() Method

firstweekday() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and returns the current setting for the weekday to start each week.

Module:

    import calendar

Syntax:

    firstweekday()

Parameter(s):

  • None

Return value:

The function returns a number from 0 to 6 where Monday indicates 0 and so on.

Example:

# 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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.