如何給 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