import os import sys import datetime start=datetime.date(1900,1,1) end=datetime.date(9999,12,31) delta=datetime.timedelta(days=1) while end>=start: a=start print(a) start+=delta 怎么看出现过多少天含有2
时间: 2023-05-25 09:06:31 浏览: 103
您可以将日期转换为字符串,然后使用字符串方法count()来计算包含数字"2"的次数。例如:
import datetime
start = datetime.date(1900,1,1)
end = datetime.date(9999,12,31)
delta = datetime.timedelta(days=1)
count = 0
while end>=start:
if "2" in str(start):
count += 1
start += delta
print("The number of days containing 2 is:", count)
这将输出包含数字"2"的天数。
阅读全文