python获取前12个月份字符串列表
比如想得到以下列表:
['2022-06', '2022-07', '2022-08', '2022-09', '2022-10', '2022-11', '2022-12', '2023-01', '2023-02', '2023-03', '2023-04', '2023-05']
即从当前月份往前推12个月份。
代码:
import datetime
year, month = datetime.datetime.now().strftime('%Y-%m'