Showing posts with the label Day of Week

Featured Post

Python Regex: The 5 Exclusive Examples

 Regular expressions (regex) are powerful tools for pattern matching and text manipulation in Python. Here are five Python regex examples with explanations: 01 Matching a Simple Pattern import re text = "Hello, World!" pattern = r"Hello" result =, text) if result:     print("Pattern found:", Output: Output: Pattern found: Hello This example searches for the pattern "Hello" in the text and prints it when found. 02 Matching Multiple Patterns import re text = "The quick brown fox jumps over the lazy dog." patterns = [r"fox", r"dog"] for pattern in patterns:     if, text):         print(f"Pattern '{pattern}' found.") Output: Pattern 'fox' found. Pattern 'dog' found. It searches for both "fox" and "dog" patterns in the text and prints when they are found. 03 Matching Any Digit   import re text = "The price of the

Python How to Find Day of the Week

DAY of the week Python code you will know here. One is from Calendar, and another one is from a function. Here, I have given my ideas on a better method. Also, the result you can get in a tuple. You might also like Attitude is Everything That Changes Your Life. Day of Week and Day_Name Monday 0 Tuesday 1 Wednesday 2 Thursday 3 Friday 4 Saturday 5 Sunday 6 Python: Day of Week How to Calculate 1. Python Logic to get Day of Week from Calendar from datetime import datetime import calendar dt = dn = dt.weekday() print ("Today is day number: {0}".format(dn)) print ("Today is a {0}".format(calendar.day_name[dn])) Here, the print uses string.format method to print output. Check out   the best example to use this method . The Output The result from the first logic Instead of directly using DateTime, you can write a function - that creates a tuple with Day of week and Day name. 2. Python Logic to get Day and Day_name  User defined function from datetime i