Python calendar weekheader() Method with Example

Python calendar.weekheader() Method: In this tutorial, we will learn about the weekheader() method of calendar module in Python with its usage, syntax, and examples. By Hritika Rajput Last updated : April 24, 2023

Python calendar.weekheader() Method

The calendar.weekheader() method is an inbuilt method of the calendar module, it returns a header containing the abbreviated names of the weekday.

Module

The following module is required to use weekheader() method:

import calendar

Syntax

The following is the syntax of weekheader() method:

weekheader(n)

Parameter(s)

The following are the parameter(s):

  • n: It is a required parameter, which represents the width in characters for one weekday.

Return Value

The return type of this method is <class 'str'> (a string), it returns a header containing abbreviated weekday names.

Example of calendar.weekheader() Method in Python

## Python program to illustrate the 
## use of weekheader() method
  
# importing calendar module 
import calendar 

n = 1
print("When width in character for one weekday = 1")
print(calendar.weekheader(n))
print()

n = 3
print("When width in character for one weekday = 3")
print(calendar.weekheader(n))
print()

n = 5
print("When width in character for one weekday = 5")
print(calendar.weekheader(n))
print()

n = 10
print("When width in character for one weekday = 10")
print(calendar.weekheader(n))
print()

n = 15
print("When width in character for one weekday = 15")
print(calendar.weekheader(n))

Output

When width in character for one weekday = 1
M T W T F S S

When width in character for one weekday = 3
Mon Tue Wed Thu Fri Sat Sun

When width in character for one weekday = 5
 Mon   Tue   Wed   Thu   Fri   Sat   Sun 

When width in character for one weekday = 10
  Monday    Tuesday   Wednesday   Thursday    Friday    Saturday    
  Sunday  

When width in character for one weekday = 15
     Monday         Tuesday        Wednesday        Thursday         
     Friday         Saturday         Sunday 



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.