如何在python中将月份数转换为月份名

use*_*183 8 numbers list python-3.2

如何获得与用户输入相对应的列表.如果我有一个列表如下:

month_lst = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
              'August', 'September', 'October', 'November', 'December']
Run Code Online (Sandbox Code Playgroud)

如何输入1作为答案返回"1月"?

input('Enter the number to be converted: ')
Run Code Online (Sandbox Code Playgroud)

此外,输入需要检查列表以确保它在1-12之内,因此输入15将读取错误消息.

小智 14

日历库可以提供您想要的内容,请参阅http://docs.python.org/2/library/calendar.html上的文档

calendar.month_name[month_number] #for the full name 
Run Code Online (Sandbox Code Playgroud)

要么

calendar.month_abbr[month_number] #for the short name
Run Code Online (Sandbox Code Playgroud)