# python 條件運算子(三目運算子)
###### tags: `python` `if` `縮排` `區分大小寫`
# 語法
條件成立執行的表達式 if 條件 else 條件不成立執行的表達式
---
a = 1
b = 2
c = a if a > b else b
print(c)
---
![](https://i.imgur.com/5t9Tm5a.png)
---
![](https://i.imgur.com/eXPmVE2.png)
---
![](https://i.imgur.com/tpNTalq.png)
# 條件式總結
# if 語句
# if else
---
![](https://i.imgur.com/VB9H63Q.png)
# 多重判斷
if
elif
else
# if 嵌套
![](https://i.imgur.com/qVhlmHu.png)
# 條件運算
![](https://i.imgur.com/xY8rg7B.png)