在本教程中,我们将学习如何使用 Python 显示任何年份的任何月份的日历。
在下面的代码中,我们将导入“日历”模块。它有一个内置的“month()”函数,该函数获取用户想要显示日历的年和月。
示例:
import calendar
year = int(input ("Please enter the Year: ")) # Here, it will take the year
month = int(input ("Please enter the month: ")) # Here, it will take the month
# Now, we will display the calendar
Print ("The Calendar of: ", calendar.month(year, month))
<
输出:
案例-1
Please enter the Year: 1919
Please enter the month: 01
The Calendar of: January 1919
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 31
案例-2
Please enter the Year: 2022
Please enter the month: 10
The Calendar of: October 2022
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
31
结论
在本教程中,我们讨论了用户如何在 Python 中显示日历。