finding last business day of a month in python

前端 未结 6 1157
半阙折子戏
半阙折子戏 2020-12-31 08:33

I\'m trying to find last business day of of the month. I wrote the code below for that and it works fine but I was wondering if there is a cleaner way of doing it?

6条回答
  •  忘掉有多难
    2020-12-31 09:12

    For one-liner fans:

    import calendar
    
    def last_business_day_in_month(year: int, month: int) -> int:
        return max(calendar.monthcalendar(year, month)[-1:][0][:5])
    

提交回复
热议问题