Python 获取年份列表

标签 python

我需要获得过去 5 年的 Python 经验。我希望在一次漂亮的整洁行中做到这一点。但我能想到的最好的就是这个。

year = datetime.datetime.today().year
YEARS = [year, year-1, year-2, year-3, year-4, year-5]

还有更好的方法吗?

最佳答案

这可以帮助:

>>> range(year, year - 6, -1)
[2016, 2015, 2014, 2013, 2012, 2011]

关于Python 获取年份列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35042336/

相关文章:

python - 如何使用嵌套循环反转此模式?

python - 具有变量值的 Django 查询集

python - Pandas 多层次分组

python - 有条件地询问键是否存在以及在 python 中是否为真

python - 为什么读取一个字节比从文件中读取 2、3、4……字节慢 20 倍?

python - python中的sha-256散列

python - 为什么我的正则表达式不能用于字符验证

python - 是否有更短的代码来连接字典的键和值?

python - 如何设置只有整数的 x 轴刻度线?

python - 创建一个可以被 conda 环境中的 jupyter Notebook 理解的 python 模块