PHP前端开发

用python怎么编写输入月份并输出月份天数

百变鹏仔 1个月前 (01-22) #Python
文章标签 天数

python中对日期的计算可以使用calendar模块。

实现代码如下:

#!/usr/bin/python3import calendaryear = input("请输入年份:")month = input("请输入月份:")year = int(year)month = int(month)monthRange = calendar.monthrange(year,month)print("%d年%d月有%d天" % (year,month,monthRange[1]))

效果如下:

更多Python相关技术文章,请访问Python教程栏目进行学习!

立即学习“Python免费学习笔记(深入)”;