To check if the current day is a weekday or weekend in python we need to import the datetime() package and use an if-else statement to classify the days.
Step 1: Import datetime package and date
import datetime from datetime import date
The date time package supplies us with the tools to manipulate and grab the current day’s value.
Step 2: Grab the week number using datetime
weeknumber = datetime.date.today().weekday()
Next, we need to grab the current week’s number and assign it to a variable.
The DateTime package assigns the days of a week by assigning them with index numbers, where 0 is a Monday and 6 is a Sunday.
Step 3: Create an if-else statement to classify the day
if weeknumber < 5: # 0 Mon, 1 Tue, 2 Wed, 3 Thus, 4 Fri print("Today Is A Weekday) else: # 5 Sat, 6 Sun print("Today is A weekend)
Lastly, we will just use a simple if else statement, where the numbers less than 5 (Saturday) is a weekday and else statement where a value is greater than or equal to 5 is a weekend.