📜  python 在 for 循环中分配列表项 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:06.430000             🧑  作者: Mango

代码示例1
year = 2021
month_list = [1, 2, 3, 4, 5]
day = 1
date_list = []

for month in month_list:
    date_list.append( datetime(year, month, day).strftime("%Y-%m-%d") )

print(date_list)    
# ['2021-01-01', '2021-02-01', '2021-03-01', '2021-04-01', '2021-05-01']