为什么“if(年%100)== 0:”用来? [英] Why "if (year % 100) == 0:" is used?

查看:171
本文介绍了为什么“if(年%100)== 0:”用来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# Python program to check if the input year is a leap year or not

year = 2000

if (year % 4) == 0:
   if (year % 100) == 0:
       if (year % 400) == 0:
           print("{0} is a leap year".format(year))
       else:
           print("{0} is not a leap year".format(year))
   else:
       print("{0} is a leap year".format(year))
else:
   print("{0} is not a leap year".format(year))





我的尝试:



i不明白为什么使用它。



What I have tried:

i do not understand why that is used.

推荐答案

参见 5。表达式 - Python 2.7.15rc1文档 [ ^ ]

See 5. Expressions — Python 2.7.15rc1 documentation[^]
Quote:

%(modulo)运算符产生余数来自第二个参数除以第二个参数。

The % (modulo) operator yields the remainder from the division of the first argument by the second.


Quote:

为什么if(year%100)== 0:使用?

Why "if (year % 100) == 0:" is used?



你需要研究闰年,它不仅每4年一次,而且更复杂一点。

闰年 - 维基百科 [ ^ ]


这篇关于为什么“if(年%100)== 0:”用来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆