Python,True/False,将函数集成到程序中

标签 python boolean

我对 python 比较陌生。我想制作一个程序来检查日期是否有效。到目前为止,我编写了函数代码来检查闰年。但我想集成到更大的程序中来检查月份和日期的有效性。我怎么能在最后一行说“当 C 为 true 时继续执行某个 if else 逻辑(...我稍后将编写的代码)”和“当 C 为 false 时继续执行另一个 if else 逻辑”

def leap_year(c):

    if c % 4 == 0 and y % 100 != 0:
        print("True (Non-Centurial)")
    else:
        if c % 400 == 0:
            print("True (Centurial)")
        else:
            print("False")
    pass



    for c == True:

    ...(my if else statements)

最佳答案

您可以使用 elif 关键字实现 if-else 结构:

if c % 4 == 0 and y % 100 != 0:
    print("True (Non-Centurial)")
elif c % 400 == 0:
    print("True (Centurial)")
elif condition1:
    pass
elif contition2:
    pass
else
    print("False")

关于Python,True/False,将函数集成到程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35210132/

相关文章:

python - Anaconda 加速 check_cuda()

python - 如何在Django中引用不同应用程序中的不同模板?

python - boolean 值与 float 相乘?

ios - swift : How to check if UserDefaults exists and if not save a chosen standard value?

excel - 简单的 boolean 值和表达式

python - Matplotlib 动画迭代 pandas 数据帧列表

Python Pyglet 使用外部字体作为标签

python - 当重复仅在第一列时,pandas 中 drop_duplicates

c# - 如何在 C# 中将 Cast null 类型转换为 Bool?

javascript - 有兴趣使用双 boolean 否定吗?