I'm a total noob in Python and I'm currently reading a script provided by a colleague. I got confused with the below script having it run today.
import datetime
today=datetime.date.today() - datetime.timedelta(days=4)
print (today)
if today.weekday() in [range(0,7)]:
saturday=today-datetime.timedelta(today.weekday()-5)
sunday=today-datetime.timedelta(today.weekday()-6)
else:
saturday=today-datetime.timedelta(today.weekday()+2)
sunday=today-datetime.timedelta(today.weekday()+1)
print (saturday)
print (sunday)
print (today.weekday())
Below is the result:
2018-07-19
2018-07-14
2018-07-15
3
Why is the script executing the one in else-statement?
The today.weekday() results to 3 which should've executed the if-statement since 3 is within the range which if manually computed saturday = 2018-07-21.
Kindly advise where I have it understood incorrectly.
today.weekday() in range(0,7)will always evaluate toTrueso the else statement is not reachable