如何使用 Python 找到指定年份的第一天?
在本程式中,我們必須列印年份的第一天。我們必須根據使用者輸入獲取年份。
演算法
Step 1: Import the datetime library. Step 2: Take year as input from the user. Step 3: Get the first day of the year by passing month, day and year as parameters to the datetime.datetime() function Step 4: Display the first day using strftime() function.
示例程式碼
import datetime
year = int(input("Enter year: "))
firstday = datetime.datetime(year, 1,1)
print("First Day of ", year, " = ", firstday.strftime("%A"))輸出
First Day of 2021 = Friday
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP