itermonthdays2()

Calendar Module

monthMonth number for which dates are requried
yearYear number for which dates are requried
itermonthdays2() : Returns an Iterator of tuples having days of the month and week day number.

Note that days will be returned as 0 per the days for the week starting from Previous month and for days for the week extended up to next month. This is our first or 0th element of the tuple.

Week day number starts from 0 as Monday , 1 as Tuesday and ends at 6 as Sunday. This is our second or 1th element of the tuple.
import calendar
my_cal= calendar.Calendar()
for x in my_cal.itermonthdays2(2020,7):
	print(x)
Output
(0, 0)
(0, 1)
(1, 2)
(2, 3)
(3, 4)
(4, 5)
(5, 6)
(6, 0)
------
------
(27, 0)
(28, 1)
(29, 2)
(30, 3)
(31, 4)
(0, 5)
(0, 6)
By updating the first day of the week we can get different elements of the iterator.
import calendar
my_cal= calendar.Calendar(firstweekday=3)
for x in my_cal.itermonthdays2(2020,7):
	print(x)
Output
(0, 3)
(0, 4)
(0, 5)
(0, 6)
(0, 0)
(0, 1)
(1, 2)
----
----
----
(30, 3)
(31, 4)
(0, 5)
(0, 6)
(0, 0)
(0, 1)
(0, 2)
As we are getting tuple as output, we can get first element as day number and second element as day of the week.
import calendar
my_cal= calendar.Calendar(firstweekday=3)
for x in my_cal.itermonthdays2(2020,7):
	print('day:',x[0],', weekday : ',x[1])
Output
day: 0 , weekday :  3
day: 0 , weekday :  4
day: 0 , weekday :  5
day: 0 , weekday :  6
day: 0 , weekday :  0
day: 0 , weekday :  1
day: 1 , weekday :  2
day: 2 , weekday :  3
---------------------
---------------------
day: 29 , weekday :  2
day: 30 , weekday :  3
day: 31 , weekday :  4
day: 0 , weekday :  5
day: 0 , weekday :  6
day: 0 , weekday :  0
day: 0 , weekday :  1
day: 0 , weekday :  2
Calendar Module in Python itermonthdays() only days of the month itermonthdays3() itermonthdays4()




plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer