如何在 Python 的多行 if 語句中註釋每個條件?
如果你在圓括號中包圍了多行 if 語句條件,則可以直接做到。例如,
if (cond1 == 'val1' and cond2 == 'val2' and # Some comment cond3 == 'val3' and # Some comment cond4 == 'val4'):
但是,如果你試圖在沒有圓括號的情況下這樣做,這是不可能的。例如,以下程式碼會產生錯誤
if cond1 == 'val1' and \ cond2 == 'val2' and \ # Some comment cond3 == 'val3' and \ # Some comment cond4 == 'val4':
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
JavaScript
PHP