本文共 3052 字,大约阅读时间需要 10 分钟。
python 示例
prmonth() method is an inbuilt method of the TextCalendar class of calendar module in Python. It works on text calendars. It uses an instance of TextCalendar class and prints the month of the given year. Also, there is no need for writing "print" operation.
prmonth()方法是Python中日历模块的TextCalendar类的内置方法。 它适用于文本日历。 它使用TextCalendar类的实例并打印给定年份的月份。 同样,也不需要编写“打印”操作。
Module:
模块:
import calendar
Class:
类:
from calendar import TextCalendar
Syntax:
句法:
prmonth(year, month, w=0, l=0)
Parameter(s):
参数:
year: It is a required parameter, which specifies the year of the calendar.
year :这是必填参数,用于指定日历的年份。
month: It is a required parameter, which specifies the month of the calendar.
month :这是必填参数,用于指定日历的月份。
w: It is an optional parameter, which specifies the width of the date column; default value = 0.
w :这是一个可选参数,用于指定日期列的宽度; 默认值= 0。
l: It is an optional parameter, which represents the number of lines one week would use in the resulting string, default value = 0.
l :这是一个可选参数,表示一周后将在结果字符串中使用的行数,默认值为0。
Return value:
返回值:
The return type of this method is <class 'NoneType'>, it prints the corresponding calendar of the given year's month.
此方法的返回类型为<class'NoneType'> ,它打印给定年份月份的相应日历。
Example:
例:
# Python program to illustrate the # use of prmonth() method# import classimport calendar# creating a TextCalendar instancecal = calendar.TextCalendar()year = 2019month = 12print("Printing December 2019 calendar with default paramters, w = 0, l = 0")cal.prmonth(year, month)print()# Setting width=3 cal = calendar.TextCalendar()year = 1919month = 1print("Printing January 1919 calendar with w = 3")cal.prmonth(year, month, 3)print()# Setting width=5 length of one line=2 cal = calendar.TextCalendar()year = 1999month = 11print("Printing November 1999 calendar with w = 3, l = 2")cal.prmonth(year, month, 3, 2)print()# Changing the firstweekdaycal = calendar.TextCalendar(firstweekday = 4)# First column will be Fridayyear = 2005month = 5print("Printing May 2005 calendar with w = 3, l = 1 and first column starting with Friday")cal.prmonth(year, month, 3, 1)print()
Output
输出量
Printing December 2019 calendar with default paramters, w = 0, l = 0 December 2019Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31Printing January 1919 calendar with w = 3 January 1919Mon Tue Wed Thu Fri Sat Sun 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 31Printing November 1999 calendar with w = 3, l = 2 November 1999Mon Tue Wed Thu Fri Sat Sun 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 30Printing May 2005 calendar with w = 3, l = 1 and first column starting with Friday May 2005Fri Sat Sun Mon Tue Wed Thu 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
翻译自:
python 示例
转载地址:http://dwvzd.baihongyu.com/