how to find current day is weekday or weekends in Python?

Question:

Please suggest me on the following.
How to find whether a particular day is weekday or weekend in Python?

Asked By: vinay h

||

Answers:

Use the date.weekday() method. Digits 0-6 represent the consecutive days of the week, starting from Monday.

Answered By: Michał Szydłowski

You can use the .weekday() method of a datetime.date object

import datetime

weekno = datetime.datetime.today().weekday()

if weekno < 5:
    print "Weekday"
else:  # 5 Sat, 6 Sun
    print "Weekend"
Answered By: fahad
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.