ADVERTISEMENT
ADVERTISEMENT

Python calendar Module | setfirstweekday() Method with Example

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

Python calendar.setfirstweekday() Method

setfirstweekday() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and sets 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:

    import calendar

Syntax:

    setfirstweekday(weekday)

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:

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