--- title: 【Python】三元運算子 date: 2018-12-13 is_modified: false disqus: cynthiahackmd categories: - "程式設計 › 程式語言與架構" tags: - "Python" --- {%hackmd @CynthiaChuang/Github-Page-Theme %} <br> 在 Jave 或 JavaScript 中的三元運算子是 ```shell= 判斷式 ? 若判斷為真執行區塊 : 若判斷為假執行區塊 ``` 但這不適用於 Python。 <!--more--> <br> 在 Python 中沒有 `?:` ,而是類似 `if...else` 的寫法 ```python= 若判斷為真執行區塊 if 判斷式 else 若判斷為假執行區塊 ``` ## 參考資料 1. [6. Ternary Operators|Python Tips 0.1 documentation](https://book.pythontips.com/en/latest/ternary_operators.html) <br><br> > **本文作者**: 辛西亞.Cynthia > **本文連結**: [辛西亞的技能樹](https://cynthiachuang.github.io/Python-Ternary-Operators) / [hackmd 版本](https://hackmd.io/@CynthiaChuang/Python-Ternary-Operators) > **版權聲明**: 部落格中所有文章,均採用 [姓名標示-非商業性-相同方式分享 4.0 國際](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en) (CC BY-NC-SA 4.0) 許可協議。轉載請標明作者、連結與出處!
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up