怎么把m==1…用更简洁的方法表示,为什么用m==(…)不好使

img


如题,有什么更好的表示多个元素的方法为什么m==(…,……,…)不好使呢


x = int(input())#获取年份
y = int(input())#获取月份
#  月份天数初始化列表,索引代表月份
# 0 占位用的
month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]


def is_leap(year):
    """返回 True 闰年, False 非闰年."""
    # 能被4整除且(不能被100整除或能被400整除)
    return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)


def days_in_month(year, month):
    """返回当年当月天数"""

    if not 1 <= month <= 12:
        return '无效月份 Month'

    if month == 2 and is_leap(year):
        return 29
    # 返回month索引值对应的月天数
    return month_days[month]

print(days_in_month(x, y))


换成列表就好了,判断是否在列表里。

y = int(input())
m = int(input())

if m in [1,3,5,7,8,10,12]:
    pass
elif m in [4,6,9,11]:
    pass
else:
    # 二月
    pass

switch也行呀,不用写==