可以使用datetime庫中的date類來判斷一年中的第幾天。下面是一個示例代碼:
from datetime import date
def day_of_year(year, month, day):
d = date(year, month, day)
return d.timetuple().tm_yday
year = 2022
month = 3
day = 15
day_number = day_of_year(year, month, day)
print("第{}天".format(day_number))
這個代碼會輸出:第74天