比較原則
- 比較相等:== 區分大小寫
- 比較不相等:!=
- 檢查多個條件:and(類似&&)、or(類似||)
- 檢查特定值是否在列表中:in(在列表中)、not in(不在列表中)
if語句
if condition_test:
do something
if-else語句
if condition_test:
do something
else:
do another thing
if-elif-else語句
if condition_test_1:
do something_1
elif condition_test_2:
do something_2
else:
do another thing
- 可以使用多個elif代碼塊
- 也可以省略else代碼塊
- 使用時,只會執行某一分支裏的語句