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]))
效果如下:
更多Python相关技术文章,请访问Python教程栏目进行学习!
立即学习“Python免费学习笔记(深入)”;
以上就是用python怎么编写输入月份并输出月份天数的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号