2 回答

TA貢獻1752條經驗 獲得超4個贊
您提供了選項 {1, 2, 3}。
絕對使用 2 或 3。這是它們之間的品味問題,或者您最喜歡的編輯器鼓勵您使用的內容。(將所有內容放在一行,光標越過打開的括號,點擊 RETURN,并使用建議的縮進。)只要
$ flake8
不抱怨,你是金子。(得到它pip install flake8。)
對于大量參數或涉及冗長表達式的參數,您甚至可以考慮每行列出一個參數。
如果您要分配很多長標識符,您可以考慮在元組解包時將 LHS 括在括號中:
(detector_x, detector_y,
smeared_x, smeared_y) = gamma_detection(
decay_positions,
cos_theta + epsilon * some_long_expression(),
phi)

TA貢獻1831條經驗 獲得超10個贊
在 VS 代碼上使用 autopep8,您的代碼將更改為以下內容:
detector_x, detector_y, smeared_x, smeared_y = \
gamma_detection(decay_positions, cos_theta, phi)
現在我看了一下總長度,如果這是單行的話,是 96 個字符。即使這超出了 PEP8 的約 79 個字符的限制,我仍然建議將其保留為一行。在實踐中,79 個字符非常短,如果您制作 100 個字符的行,可讀性不會降低。在我工作的地方,我們還將行長度的準則增加到 100 個字符。
# 96 characters
detector_x, detector_y, smeared_x, smeared_y = gamma_detection(decay_positions, cos_theta, phi)
添加回答
舉報