您好,欢迎来到汇意旅游网。
搜索
您的当前位置:首页用python怎么编写输入月份并输出月份天数

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

来源:汇意旅游网

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

实现代码如下:

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

效果如下:

1.jpg

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

Copyright © 2019- hids.cn 版权所有 赣ICP备2024042780号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务