當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python calendar itermonthdays()用法及代碼示例


日曆模塊允許輸出類似於程序的日曆,並提供與日曆相關的其他有用函數。 “日曆”模塊中定義的函數和類使用理想化的日曆,當前的公曆日曆在兩個方向上都無限期擴展。

itermonthdays()方法返回指定月份和年份的迭代器。返回的天數僅僅是天數。itermonthdays()方法類似於itermonthdates()

用法: itermonthdays(year, month)

參數: 
year: year of the calendar
month: month of the calendar

返回: an iterator of the specified month.

代碼1:


# Python program to demonstrate working 
# of itermonthdays() method 
  
# importing calendar module 
import calendar 
  
year = 2018
mnth = 9
  
  
obj = calendar.Calendar() 
  
# iteratign with itermonthdays 
for day in obj.itermonthdays(year, mnth):
    print(day)

輸出:

0
0
0
0
0
1
2
3
4
5
6
.
.
29
30

代碼2:

# Python program to demonstrate working 
# of itermonthdays() method 
  
# importing calendar module 
import calendar 
  
# use with firstweekday = 5 
obj = calendar.Calendar(firstweekday = 2) 
  
# iteratign with itermonthdays 
for day in obj.itermonthdays(2018, 4):
    print(day)

輸出:

0
0
0
0
1
2
3
4
5
.
.
28
29
30
0


相關用法


注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python calendar module | itermonthdays() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。