python 示例_Python TextCalendar类别| prmonth()方法与示例

python 示例

Python TextCalendar.prmonth()方法 (Python TextCalendar.prmonth() Method)

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 class
import calendar

# creating a TextCalendar instance
cal = calendar.TextCalendar()
year = 2019
month = 12
print("Printing December 2019 calendar with default paramters, w = 0, l = 0")
cal.prmonth(year, month)
print()

# Setting width=3 
cal = calendar.TextCalendar()
year = 1919
month = 1
print("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 = 1999
month = 11
print("Printing November 1999 calendar with w = 3, l = 2")
cal.prmonth(year, month, 3, 2)
print()

# Changing the firstweekday
cal = calendar.TextCalendar(firstweekday = 4)
# First column will be Friday
year = 2005
month = 5
print("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 2019
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 31

Printing January 1919 calendar with w = 3
        January 1919
Mon 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  31

Printing November 1999 calendar with w = 3, l = 2
       November 1999

Mon 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


Printing May 2005 calendar with  w = 3, l = 1 and first column starting with Friday
          May 2005
Fri 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


翻译自: https://www.includehelp.com/python/textcalendar-prmonth-method-with-example.aspx

python 示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值