Answers for "python assign list item in for loop"

0

python assign list item in for loop

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']
Posted by: Guest on May-21-2021

Code answers related to "python assign list item in for loop"

Python Answers by Framework

Browse Popular Code Answers by Language