python 三元運算符

|

Python 中沒有三元運算符。但它確實支持編寫 if-else 語句,使其像三元運算符一樣工作。

為什麼 Python 沒有特殊的三元運算符?

許多編程語言都有三元運算符。但他們的主要目標是&通過刪除簡單的 if-else 塊來減少代碼大小。 Python 改進了 if-else 語句以減少代碼的大小,而不是添加額外的語句。

Python 實現

Python 中模擬三元運算符的語法是

< script async src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle .js?client = ca-pub-6959883099270890" crossorigin = "anonymous"> < ins class = "adsbygoogle" style = "display: inline-block; width: 336px; height: 280px" data-ad-client = "ca-pub-6959883099270890" data-ad-slot = "3943413939" >

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method