在 Python 中如何縮排多個 if...else 語句?
使用縮排塊是 Python 的一個重要特性。塊的縮排級別高於前面的語句。因此,如果程式中有多個 if 語句巢狀在一起,那麼每個後續的縮排塊的縮排級別都會增加。
if expr1==True: if expr2==True: stmt1 else: if expr3==True: stmt2 else: if expr3==True: stmt3 else: stmt4
廣告
使用縮排塊是 Python 的一個重要特性。塊的縮排級別高於前面的語句。因此,如果程式中有多個 if 語句巢狀在一起,那麼每個後續的縮排塊的縮排級別都會增加。
if expr1==True: if expr2==True: stmt1 else: if expr3==True: stmt2 else: if expr3==True: stmt3 else: stmt4