In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the methods of Python calendar module". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the methods of Python calendar module".
1. Overview of calendar module
The calendar module provides practical functions related to calendars to help us get calendar-related information.
Characteristics of 1.1calendar
The calendar module calculates the number of weeks per week based on datetime.date.weekday () pairs.
Calendar defaults that Monday is the first day of the week and Sunday is the last day of the week.
Calendar provides calendar.setfirstweeksday () to change the specified day of the week as the first day of the week
1.2calendar class structure
We can view the Python built-in library-calendar.py file
Calendar mainly provides three categories: Calendar, TextCalendar, and HTMLCalendar.
Where calendar is the base class of TextCalendar and HTMLCalendar
Steps for using 1.3calendar
Calendar is a built-in library, which can be imported directly using import
Import calendar2. Calendar correlation method 2.2calendar module correlation method calendar.firstweekday () sets the value of the first day of each week calendar.isleap (year) determines that it is a leap year Then return Turecalendar.leapdays (y1) to calculate the number of leap years for y1 and y2 calendar.weekday (year,month,day) returns the day of the week calendar.weekheader (n) the head of the acronym calendar.mothrange (year,month) calculates the day of the month of the specified year and the number of days of the month calendar.prmonth (theyear,themonth,w=0,1=0) formats the calendar calendar.month (theyear,themonth) of the month of the specified year Using the TextCalendar class formation () to return the month calendar calendar.prcal (year,w=1,1=0,c=6,m=3) as a multi-line string, format the calendar calendar.calendar (year,w=1,1=0,c=6) for the whole year. 3) Calendar 2.3calendar module attribute method in the form of three columns of calendar multi-line strings throughout the year to explain the calendar.day_name current locale array of the day of the week calendar.day_abbr the abbreviation of the day of the week in the current locale calendar.month_name current language array calendar.month_abbr current language month abbreviation of the next year the 2.4calendar module provides five class methods for calendar.Calendar (firstweekday=0) to create Calendar objects By default, Monday is the first day calendar.TextCalendar (firstweekday=0) generates plain text calendar object calendar.HTMLCalendar (firstweekday=0) generates HTML log object calendar.LocaleTextCalenda (firstweekday=0,locale=None) locale name calendar.LocaleHTMLCalendar (firstweekday=0,locale=None) locale name 2.5calendar.Calendar class instance related method description cal.itermonthdates (year,month) returns an iterator cal.iterweekdats () of the date of a yearyear monthmonth returns an iterator of a week's number cal.itermonthdays (year) Month) returns the number of days corresponding to the date of each day of the month For dates that are not in the current month 0cal.itermonthdays2 (year,month) returns a tuple consisting of a date and a number representing the day of the week cal.itermonthdays3 (year,month) returns a tuple of year, month and day, cal.itermonthdays4 (year,month), returns a tuple of numbers of year, month, and day, cal.monthdatescalendar (year,month), returns a weekly list of years and months made up of datetime.date objects, cal.monthdays2calendar (year) Month) returns a binary cal.monthdayscalendar (year,month) that consists of a date number and a weekly list of seven date numbers, cal.yeardatescalendar (year,width=3) returns a data list of specified years and months that can be formatted, cal.yeardays2calendar (year,width=3) returns data of a specified year and month that can be modeled. The date of this month is 0 Weekly list A tuple consisting of date and day of the week cal.yeardayscalendar (year,width=3) returns a weekly list of data consisting of dates and numbers that can be used to model data of a specified year and month 2.6calendar.TextCalendar class instance related method description tc.formatmonth (theyear,themonth,w=0,1=0) represents a calendar of a specified year and month in a multi-line string tc.prmonth (theyear,themonth,w=0,1=0) format prints a calendar of one month (theyear,w=0,1=1,c=6) M _ calendar 3) returns an m-column calendar tc.pryear (theyear,w=0,1=1,c=6,m=3) format prints calendar for a whole year 2.7calendar.HTMLCalendar class instance related method description htl.formatmonth (theyear,themonth,withyear=True) returns a specified year and month calendar htl.formatyear (theyear) of an HTML form Width=3) returns the calendar for the year specified by HTML htl.formatyearpage (theyear,width=3,css='calendar.css',encoding=None) returns a complete HTML page as the calendar for the specified year
Calendar.HTMLCalendar class instance related properties
The 2.8calendar.HTMLCalendar class instance related property method indicates that the htl.cssclasses Monday to Sunday CSS class list htl.cssclass_noday weekday CSS class occurred last month or next month htl.cssclasses_weekday_head css list for the working day name in the title line htl.cssclass_month_ headmonth CSS list title htl.cssclass_month monthly calendar CSS class htl.cssclass_year year calendar CSS class htl.cssclasses_year_head calendar CSS list title 3. Real fuck
Print the 2021 calendar
Import calendar# print 2021 Calendar print (calendar.calendar (2021))
Print a monthly calendar for a specified year
Print (calendar.month (2021 calendar.month 11)) Thank you for your reading, the above is the content of "what is the method of Python calendar module?" after the study of this article, I believe you have a deeper understanding of what the method of Python calendar module has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.