There are various formats to take out, and it seemed to be complicated, so make a note. Basically, use a module called calendar.
import calendar
cal = calendar.Calendar() #Create calendar object
# calendar.Calendar(1)You can specify the day of the week to be treated at the beginning of the week. 0~6 and the default is 0 (Monday).
###Income the schedule as decided in the above Calendar class. There are the following formats.###
cal.itermonthdays(int_year,int_month)
#Iterator format. You can take out the days in order.
cal.itermonthdays2(int_year,int_month)
#You can get the day of the week as well as the day. (Day,week_Get tuples called num) in order.
cal.itermonthdates(int_year,int_month)
#This is datetime.date(year,month,day)Form of.
cal.monthdayscalendar(int_year,int_month)
# [[0,0,1,2,3,4,5],[6,7..],[...]]With that feeling, you can take the days of each week in an array.
###Please note that the end of the month or the beginning of the month may come in during the week of the beginning or end of the month!
##By the way, if you want to know only the number of days in a month##
calendar.monthrange(int_year,int_month)
#OK. The day of the week (I wonder if it is necessary ...) and the total number of days are returned as tuples.
Recommended Posts