In this code snippet, we’ll show an example of a python language function to check if a year is a leap year.

Python language function to check if a year is a leap year

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
def is_leap_year(year: int) -> bool:
"""
Determines if a given year is a leap year.
Parameters:
year (int): The year to be checked.
Returns:
bool: True if the year is a leap year, False otherwise.
"""
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
def main():
print(is_leap_year(2400))
print(is_leap_year(2000))
print(is_leap_year(2020))
print(is_leap_year(2021))
if __name__ == "__main__":
main()
def is_leap_year(year: int) -> bool: """ Determines if a given year is a leap year. Parameters: year (int): The year to be checked. Returns: bool: True if the year is a leap year, False otherwise. """ return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) def main(): print(is_leap_year(2400)) print(is_leap_year(2000)) print(is_leap_year(2020)) print(is_leap_year(2021)) if __name__ == "__main__": main()
def is_leap_year(year: int) -> bool:
    """
    Determines if a given year is a leap year.

    Parameters:
        year (int): The year to be checked.

    Returns:
        bool: True if the year is a leap year, False otherwise.
    """
    return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)


def main():
    print(is_leap_year(2400))
    print(is_leap_year(2000))
    print(is_leap_year(2020))
    print(is_leap_year(2021))


if __name__ == "__main__":
    main()

All code from this code snippet package can be downloaded here.

MIT Licensed Code – See License

Tags: python, date, datetime, leap year, method, function, python method, python function