gpt4 book ai didi

list - 如何在Python中将月份数字转换为月份名称

转载 作者:行者123 更新时间:2023-12-02 01:38:45 28 4
gpt4 key购买 nike

如何获取与用户输入相对应的列表。如果我有一个类似的列表:

month_lst = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']

如何获得输入 1 以返回“一月”作为答案?

input('Enter the number to be converted: ')

此外,输入需要检查列表以确保其范围在 1-12 之间,因此输入 15 会显示错误消息。

最佳答案

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

calendar.month_name[month_number] #for the full name 

calendar.month_abbr[month_number] #for the short name

关于list - 如何在Python中将月份数字转换为月份名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13774649/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com