Answers for "days in month function python"

0

days in month function python

def leap_year(year):
    if year % 400 == 0:
        return True
    if year % 100 == 0:
        return False
    if year % 4 == 0:
        return True
    return False

def days_in_month(month, year):
    if month in {1, 3, 5, 7, 8, 10, 12}:
        return 31
    if month == 2:
        if leap_year(year):
            return 29
        return 28
    return 30

print(days_in_month(2, 2016))  # 29
Posted by: Guest on March-26-2021
0

convert month weeks days into month days in python pandas

>>> p = pd.Period('2018-2-17')
>>> p.days_in_month
28
Posted by: Guest on June-30-2020

Python Answers by Framework

Browse Popular Code Answers by Language