Detect months with 31 days

前端 未结 19 1662
南旧
南旧 2020-12-18 01:53

Is there an analogous form of the following code:

if(month == 4,6,9,11)
{
  do something;
}

Or must it be:

if(month == 4 ||         


        
19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 02:35

    For pretty much any you'll need to use the second option, but in most languages you can write something similar to

    if [4,6,9,11].map{|day|==month}.inject(false){|all, elem| all|elem}
        do thing
    

    or better yet

    if month in [4,6,9,11]:
        do thing
    

提交回复
热议问题