1. 首页
  2. 机器学习

显示日历的Python程序

要理解此示例,您应该了解以下Python编程主题:

  • Python模块
  • Python编程内置函数

在下面的程序中,我们导入calendar模块。month()模块内部的内置功能接收年份和月份,并显示一年中该月份的日历。

显示日历的Python程序

源代码

# Program to display calendar of the given month and year

# importing calendar module
import calendar

yy = 2014  # year
mm = 11    # month

# To take month and year input from the user
# yy = int(input("Enter year: "))
# mm = int(input("Enter month: "))

# display the calendar
print(calendar.month(yy, mm))

输出

   November 2014
Mo Tu We Th Fr Sa Su
             1  2
3  4  5  6 7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

您可以更改变量的值 yy 和 mm 并运行它以测试该程序的其他日期。

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站不拥有所有权,不承担相关法律责任。如发现有侵权/违规的内容, 联系QQ1841324605,本站将立刻清除。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

服务热线:130-0886-1890

QR code