Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the calendar module of Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to understand the calendar module of Python". In daily operation, I believe many people have doubts about how to understand the calendar module of Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to understand the calendar module of Python"! Next, please follow the editor to study!

Calendar module

This module defines many types, mainly including: Calendar, TextCalendar, HTMLCalendar, in which Calendar is the base class of TextCalendar and HTMLCalendar, these classes have very rich calendar processing methods.

At the same time, the ISO 8601 standard also specifies 0 and negative years. Year refers to 1 BC,-1 refers to 2 BC, and so on. Import before using:

Import calendar

First, let's take a look at the full calendar for 2021:

Set the first day of the week-setfirstweekday

By default: 0 for Monday and 6 for Sunday. We can use setfirstweekday () to set the first day of the week to Sunday (6) or any other day

1. Default: Monday is the first day

2. Set any day

In the following example, we set Saturday as the first day

Is it a leap year-isleap

Check whether a year is a leap year. If yes, return True, otherwise return False

The number of leap years between years-leapdays (y1, y2)

See how many leap years there are between two years. For example, in the second example, there are six leap years from 2000 to 2021.

What day of the week-weekday (year, month, day)

Check what day of the week a specific date is. For example, in the second example, November 1st is Monday, denoted by 0.

0: Monday

1: Tuesday

2: Wednesday

Monthrange (year, month)

Returns the day of the week and the number of days of the month on the first day of the specified year and month. Examples are as follows:

The first day of October is Friday, and the first day of November is Monday.

Verified by ten thousand years of history: 11.1 happens to be Monday.

Calendar matrix of the month-monthcalendar (year, month)

Returns the calendar matrix for a month:

Each line represents 1 week

By default, it starts on Monday, for example, the 1st of November happens to be Monday.

The days outside this month are indicated by zero.

Calendar of months-prmonth (year, month, w, l)

Returns an one-month calendar with a daily width interval of w characters and l is the number of lines per week

The following is the default:

You can change the parameters w and l: equal to one control column width and one control row height

Calendar for the year-calendar.calendar (year)

Use all the default parameters to view the full calendar for a year:

Format output calendar

The default parameter form is used in the results of the calendar for the output year above. In fact, the calendar method has multiple parameters:

W: width of each cell. Default is 2.

L: number of newlines per column. Default is 1.

C: the width of the interval between month and month. Default is 6.

M: divide the month into m columns

The effect displayed after changing multiple parameters:

At this point, the study on "how to understand the calendar module of Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report