Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Calendar Functions ใน Python


โมดูล calendar มีฟังก์ชันเกี่ยวกับปฏิทิน

ฟังก์ชันหลัก

ฟังก์ชันคำอธิบาย
calendar(year, w, l, c)พิมพ์ปฏิทินปีเต็ม กำหนดความกว้าง บรรทัดต่อสัปดาห์ คอลัมน์
firstweekday()คืนวันแรกของสัปดาห์ (0=Monday)
isleap(year)ตรวจสอบปีอธิกสุรทิน
leapdays(y1, y2)นับวันอธิกสุรทินระหว่างสองปี
month(year, month, w, l)พิมพ์ปฏิทินเดือนเฉพาะเดือน

ตัวอย่างโค้ด

import calendar

print(calendar.calendar(2014, 3, 1, 4))
print("First weekday:", calendar.firstweekday())
print("Is 2014 leap?", calendar.isleap(2014))
print("Leap days 1950-2000:", calendar.leapdays(1950, 2000))
print(calendar.month(2017, 6, 3, 1))

ผลลัพธ์บางส่วน

First weekday: 0
Is 2014 leap? False
Leap days 1950-2000: 12