Python: get all months in range?

后端 未结 9 1198
天涯浪人
天涯浪人 2020-12-15 18:00

I want to get all months between now and August 2010, as a list formatted like this:

[\'2010-08-01\', \'2010-09-01\', .... , \'2016-02-01\']
<
9条回答
  •  甜味超标
    2020-12-15 18:40

    You could reduce the number of if statements to two lines instead of four lines because having a second if statement that does the same thing with the previous if statement is a bit redundant.

    if (y == 2010 and m < 8) or (y == 2016 and m > 2):
        continue
    

提交回复
热议问题