isleap()方法是Python中日曆模組的內建方法。 它適用於簡單的文字日曆,並檢查給定的年份是否是leap年。 如果年份是leap年,則返回true ,否則返回false 。
Module:
模組:
import calendar
Syntax:
句法:
isleap(year)
Parameter(s):
引數:
year: the year to be checked
年 :要檢查的年份
Return value:
返回值:
The function returns true or false based on whether the year is leap or not.
該函式根據年份是否為leap年返回true或false 。
Example:
例:
# Python program to illustrate the
# use of isleap() method
# importing calendar module
print("Is year 2020 a leap year:", calendar.isleap(2020))
print()
print("Is year 1993 a leap year:", calendar.isleap(1993))
# Print leap if year is a leap year else print not leap
x = calendar.isleap(1234)
if x == True:
print("leap")
else:
print("not leap")
Output
輸出量
Is year 2020 a leap year: True
Is year 1993 a leap year: False
not leap
# Printing leap years between a range
print("Leap years between 1900 to 2000..
isleap()方法是Python中日曆模組的內建方法。 它適用於簡單的文字日曆,並檢查給定的年份是否是leap年。 如果年份是leap年,則返回true ,否則返回false 。
Module:
模組:
import calendar
Syntax:
句法:
isleap(year)
Parameter(s):
引數:
year: the year to be checked
年 :要檢查的年份
Return value:
返回值:
The function returns true or false based on whether the year is leap or not.
該函式根據年份是否為leap年返回true或false 。
Example:
例:
# Python program to illustrate the
# use of isleap() method
# importing calendar module
import calendar
print("Is year 2020 a leap year:", calendar.isleap(2020))
print()
print("Is year 1993 a leap year:", calendar.isleap(1993))
print()
# Print leap if year is a leap year else print not leap
x = calendar.isleap(1234)
if x == True:
print("leap")
else:
print("not leap")
Output
輸出量
Is year 2020 a leap year: True
Is year 1993 a leap year: False
not leap
Example:
例:
# Python program to illustrate the
# use of isleap() method
# Printing leap years between a range
# importing calendar module
import calendar
print("Leap years between 1900 to 2000..