Python:创建函数判断闰年 |
您所在的位置:网站首页 › 用java编写闰年判断函数 › Python:创建函数判断闰年 |
今天在HackerRank刷Python题,记录下Python用function判断闰年 首先 在Python中函数定义语法如下: def 函数名([参数列表]): '''注释''' 函数体 其次 闰年的判断: 能被4整除但不能被100整除或者能被400整除。 然后,相关代码如下: def is_leap(year): leap = False leap=(year%400==0 or (year%4==0 and year%100!=0)) return leap 调用的代码 year = int(input()) print(is_leap(year) 其中,可以直接return (year%400==0 or (year%4==0 and year%100!=0)) 不需要定义leap变量。 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |