好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python如何判断闰年

普通闰年:可以被4整除,不能被100整除
世纪闰年:可以被400整除
闰年天数:366天
1-12月分别为31天,29天,31天,30天,31天,30天,31天,31天,30天,31天,30天,31天

# 普通闰年
year = year%4
# 世纪闰年
year = year%400

相关推荐:《Python视频教程》

years = int(input("请输入查询的年份: "))
if (years % 4 == 0 and years % 100 != 0) or (years % 400 == 0):
    print(years, "是闰年")
else:
    print(years, "不是闰年")

执行以上代码输出结果为:

请输入查询的年份: 2019
2019 不是闰年
请输入查询的年份: 2020
2020 是闰年

以上就是python如何判断闰年的详细内容,更多请关注Gxlcms其它相关文章!

查看更多关于python如何判断闰年的详细内容...

  阅读:47次