RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Python程序:日历示例

创新互联Python教程:

在本节中,我们将通过一个例子展示如何编写一个 Python 程序来显示月历。

Python 日历示例

这个 Python 日历示例接受年和月作为输入变量。通过使用这些值,我们将显示月历。

import calendar

# ask of month and year
year = int(input("Please Enter the year Number: "))
month = int(input("Please Enter the month Number: "))

print(calendar.month(year, month))

在这个 Python 日历示例程序中,首先,我们要导入 Python 编程语言提供的日历库。该库中的一组函数可以帮助您在日历上执行许多操作。

import calendar

接下来,我们要求用户使用以下语句输入年和月的数字。为了确保他们输入的是整数值,我们在这里使用了 typecast。

year = int(input("Please Enter the year Number: "))
month = int(input("Please Enter the month Number: "))

Python 日历示例程序中的以下语句显示了月历(这里是 2016 年 2 月)。

print(calendar.month(year, month))

从上面的语句中,您可以观察到我们正在调用 python 日历库中的 month 函数。这个 Python 函数接受两个参数(即年和月)。


分享文章:Python程序:日历示例
文章URL:http://www.jxjierui.cn/article/dhdcdde.html