gpt4 book ai didi

python - 通过索引查找列表项

转载 作者:太空宇宙 更新时间:2023-11-04 11:01:35 24 4
gpt4 key购买 nike

我已经开始了。

def month(n):
lst = ['Months','Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
lst.index(x)

我需要它按如下方式工作:

>>>first = month(1)>>>first'Jan'>>> second = month(11)>>> second'Nov'

如何做到这一点?

最佳答案

def month(n):
lst = ['Months','Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
return lst[n]

关于python - 通过索引查找列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4811379/

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