有关if-elif语句格式的快速问题

Lou*_*s93 2 python if-statement

如果我想要一组if ifif语句执行单个订单; 例如:

if int(one[1]) == solution:
Run Code Online (Sandbox Code Playgroud)

if int(two[1]) == solution:
Run Code Online (Sandbox Code Playgroud)

执行一个单一的声明:

print "Hello World"
Run Code Online (Sandbox Code Playgroud)

输入此内容的最佳格式和语法正确方法是什么?

我试过了:

if int(two[1]) == solution::
    elif int(one[1]) == solution:
        print "Hello World"
Run Code Online (Sandbox Code Playgroud)

和其他变化,但不能把我的数字放在正确的方法来做到这一点.请温柔StackOverflow,我没有编程太久.

我正在编程的语言是Python.谢谢!

更新:

我认为这是正确的答案,而不是和阿卜杜勒卡德尔.谢谢你们两位.在Python中我想我会输入:

if (int(one[1]) == solution OR int(two[1])== solution)):
         print "Hello World"
Run Code Online (Sandbox Code Playgroud)

Evp*_*pok 9

如果要在两个条件都为真时打印它,则必须使用and

if (int(one[1]) == solution) and (int(two[1]) == solution):
    print "Hello, world"
Run Code Online (Sandbox Code Playgroud)

如果你想打印它,如果一个或多个条件成立,你必须使用or相同的方式

if (int(one[1]) == solution) or (int(two[1]) == solution):
    print "Hello, world" 
Run Code Online (Sandbox Code Playgroud)

你不应该使用elif.至少如果我了解你.

elif如果if语句中的条件为假,则用于测试不同的条件,请考虑此模式

if spam:
    do_eggs() # We arrive here if spam is true
elif ham:
    do_sausages() # Here if spam was false but ham is true
else:
    print "Camelot!" # And here if both were false
Run Code Online (Sandbox Code Playgroud)

PS:

if spam:
    do_eggs()
elif ham:
    do_eggs()
Run Code Online (Sandbox Code Playgroud)

确实是一种扭曲的做法,if spam or ham: do_eggs()但它确实是丑陋的.你不敢使用它,或者你会被吹到微小的位置.