Python Check if Today is Tuesday or not Example

02-Sep-2022

.

Admin

Python Check if Today is Tuesday or not Example

Hi Dev,

Now, let's see post of Python Check if Today is Tuesday or not Code Example. We will use How to Check if Today is Tuesday in Python. This article goes in detailed on Python Today is Tuesday. I would like to show you Python Check Date is Tuesday or not.

In this example, we will use DateTime library to check whether today is Tuesday or not. I will give you two simple examples one using weekday() and another using isoweekday(). so let's see both examples:

so let's see following examples with output:

Example 1:


main.py

from datetime import datetime

# If today is Tuesday (0 = Mon, 1 = Tue, 2 = Wen ...)

if datetime.today().weekday() == 1:

print("Yes, Today is Tuesday")

else:

print("Nope...")

Output:

Yes, Today is Tuesday

Example 2:

main.py

from datetime import datetime

# If today is Monday (1 = Mon, 2 = Tue, 3 = Wen ...)

from datetime import datetime

# If today is Tuesday (1 = Mon, 2 = Tue, 3 = Wen ...)

if datetime.today().isoweekday() == 2:

print("Yes, Today is Tuesday")

else:

print("Nope...")

Output:

Yes, Today is Tuesday

#Python