2014-11-21 86 views
-7

如何在python中使用多個條件語句?如下在Pythonpython中的條件語句

if expression: 
    elif expression: 
    if expression: 
+3

請顯示你對你的問題給出的嘗試。 – 2014-11-21 11:56:14

+0

if:elif:elfi:.... else: – 2014-11-21 11:56:37

回答

2

多個條件語句可以做到的:我已經用它像

if condition1: 
    statement 
elif condition2: 
    statement 
elif condition2: 
    statement 
else: 
    statement 

或者,如果你想嵌套的條件語句:

if condition1: 
    if condition2: 
     if condition3: 
      statement 
     else: 
      statement 
    elif condition4: 
     if condition5: 
      statement 
     else: 
      statement 

(這只是一些嵌套的條件語句的一個例子)