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

วิธีเช็คว่า ปีเป็น Leap Year ใน Python

ตรวจสอบ Leap Year ด้วย Module calendar Function isleap(year) คืน True หากเป็น Leap Year มิฉะนั้น False

ตัวอย่าง

import calendar
print(calendar.isleap(1995))  # False
print(calendar.isleap(2008))  # True
print(calendar.isleap(2004))  # True

ผลลัพธ์

False
True
True