求高手帮忙,用python如何知道每月多少天,本月第一天是多少号,最后一天是多少号。求帮忙啊。

用python写出代码。 谢谢了。
就是说我这个月一共有多少天。比如现在是8月就是31天,如果9月就是30天。

import datetime
oneday = datetime.timedelta(days=1)

def themonth(year, month):
days = [datetime.date(year, month, 1),]
for x in xrange(32):
d = days[0]+x*oneday
if d.month == days[0].month:
days.append(d)
return themonth

today = datetime.date.today()
thismonth = themonth(today.year, today.month)
print thismonth[0].day # 本月第一天是多少号
print thismonth[-1].day # 最后一天是多少号追问

我q505821739.你能加我下么。高手

追答

sorry, 公司网络环境不允许即时通讯 :(
在百度hi里联系吧

温馨提示:答案为网友推荐,仅供参考