Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中从用户未输入的月份中提取月份名称?_Python - Fatal编程技术网

如何在python中从用户未输入的月份中提取月份名称?

如何在python中从用户未输入的月份中提取月份名称?,python,Python,我想知道如何使用strftime和datetime方法从用户在python中输入的月号中获取月名 我试过这个 inp=input('enter the month no ') a=datetime.date(inp).strftime("%B") print(a) 请告诉我正确的代码您需要创建一个包含年、月和日的日期对象,因此请为这些参数包含垃圾值 inp=input('enter the month no ') a=datetime.date(1, int(inp), 1).strftime

我想知道如何使用strftime和datetime方法从用户在python中输入的月号中获取月名

我试过这个

inp=input('enter the month no ')
a=datetime.date(inp).strftime("%B")
print(a)

请告诉我正确的代码

您需要创建一个包含年、月和日的日期对象,因此请为这些参数包含垃圾值

inp=input('enter the month no ')
a=datetime.date(1, int(inp), 1).strftime("%B")
print(a)

是的,我明白了,非常感谢