关于#python#的问题:怎么用python程序,打印出2020-2023年的按月的日期

打印出2020-2023年的按月的日期,格式为“2020年1月”。

已有year=[2020,2021,2022,2023]

使用calendar库遍历年份月份,输出日历。参考代码:

year=[2020,2021,2022,2023]
import calendar
for x in year:
    print(f'{x}年:')
    for y in range(1,13):
        print(f'{y}月:')
        cal = calendar.month(x, y)        
        print(cal)

如有帮助,请点击采纳按钮支持。

可以通过:导入
import calendar

x :2020
循环:
y = 1
while y<13:
cal = calendar.month(x, y)
print('以下输出' + str(x) + '年' + str(y) + '月')

year=[2020,2021,2022,2023]
month=[1,2,3,4,5,6,7,8,9,10,11,12]
for i in year:
for j in month:
print('{}年{}月'.format(i,j))