Python定义了一个内置模块“ 日历 “它处理与日历相关的操作。 手术 这个 日历: 1.日历(年份,w,l,c) :-此函数显示年份、字符宽度、每周行数和列分隔。 2.第一个工作日 :-此函数返回 第一周天数 .默认情况下为0(星期一)。
null
Python3
# Python code to demonstrate the working of # calendar() and firstweeksday() # importing calendar module for calendar operations import calendar # using calendar to print calendar of year # prints calendar of 2012 print ( "The calendar of year 2012 is : " ) print (calendar.calendar( 2012 , 2 , 1 , 6 )) #using firstweekday() to print starting day number print ( "The starting day number in calendar is : " ,end = "") print (calendar.firstweekday()) |
输出:
The calendar of year 2012 is : 2012 January February MarchMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 1 2 3 4 2 3 4 5 6 7 8 6 7 8 9 10 11 12 5 6 7 8 9 10 11 9 10 11 12 13 14 15 13 14 15 16 17 18 19 12 13 14 15 16 17 1816 17 18 19 20 21 22 20 21 22 23 24 25 26 19 20 21 22 23 24 2523 24 25 26 27 28 29 27 28 29 26 27 28 29 30 3130 31 April May JuneMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 6 1 2 3 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 1716 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 2423 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 3030 July August SeptemberMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 1 2 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 1616 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 2323 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 3030 31 October November DecemberMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 1 2 3 4 1 2 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 915 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 1622 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 2329 30 31 26 27 28 29 30 24 25 26 27 28 29 30 31The starting day number in calendar is : 0
3.isleap(年) :-此函数检查参数中提到的年份是否为 A. 跳还是不跳 . 4.跳跃日(第1年、第2年) :-此函数返回 指定年份之间的闰日数 在争论中。
Python3
# Python code to demonstrate the working of # isleap() and leapdays() # importing calendar module for calendar operations import calendar # using isleap() to check if year is leap or not if (calendar.isleap( 2008 )): print ( "The year is leap" ) else : print ( "The year is not leap" ) #using leapdays() to print leap days between years print ( "The leap days between 1950 and 2000 are : " ,end = "") print (calendar.leapdays( 1950 , 2000 )) |
输出:
The year is leapThe leap days between 1950 and 2000 are : 12
5.月(年、月、w、l) :-此函数用于打印 特定年份的月份 在辩论中提到。 它需要4个参数,年、月、字符宽度和一周的行数 .
Python3
# Python code to demonstrate the working of # month() # importing calendar module for calendar operations import calendar # using month() to display month of specific year print ( "The month 5th of 2016 is :" ) print (calendar.month( 2016 , 5 , 2 , 1 )) |
输出:
The month 5th of 2016 is : May 2016Mo 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 31
本文由 曼吉星 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END