Software engineering and personal development

Month: December 2022

3 Ways How You Can Quickly Check Whether a Year is a Leap Year in Python

A 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 reading

How to Get the Number of Days in a Month in Python

If 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 calendar
 ​
 # Get current month
 _, number_of_days = calendar.monthrange(2023, 2)
 ​
 print(number_of_days)  # 28
Continue reading

© 2024 Fatos Morina

Theme by Anders NorenUp ↑