The majority of the world puts days in front of months in their dates:
However, there can be cases when you get as input a date where the month is in front of the day.
Continue readingSoftware engineering and personal development
The majority of the world puts days in front of months in their dates:
However, there can be cases when you get as input a date where the month is in front of the day.
Continue readingA leap year is a year that has 366 days instead of the usual 365. It occurs every four years and is the year when an extra day, February 29th, is added to the calendar. This day, known as a leap day, helps to keep the calendar aligned with the Earth’s movements around the sun. Leap years occur every four years, with the next one occurring in 2024.
We can check whether a year is a leap year in Python in a few ways.
Continue readingIf you need to get the number of days in a month in Python, you can do that quite quickly.
We are going to do that using the calendar
module.
First, import the calendar
module and then call the method monthrange()
which returns the first_day
and also the number_of_days
in a month.
Let us see this in action:
import calendarContinue reading
# Get current month
_, number_of_days = calendar.monthrange(2023, 2)
print(number_of_days) # 28
In some companies, they pay their employees on the first day of every month.
If you want to know what day of the week will that be, you can find that quickly in Python using the calendar
module.
Let us assume that you want to check the first day of the next month:
import calendarContinue reading
first_day, _ = calendar.monthrange(2022, 12)
© 2025 Fatos Morina
Theme by Anders Noren — Up ↑