0
'=' not in access and name + '.' not in access
可以避免這一行的重複?
我希望避免在一行Python代碼中使用多個not in access
s。爲了方便起見,我使用了表達式評估循環來處理重複次數較多的情況,但在兩處似乎很奇怪。
'=' not in access and name + '.' not in access
可以避免這一行的重複?
我希望避免在一行Python代碼中使用多個not in access
s。爲了方便起見,我使用了表達式評估循環來處理重複次數較多的情況,但在兩處似乎很奇怪。
這裏的另一種選擇:
all(s not in access for s in ('=', name + '.'))
它是由你來決定這是不是比你的代碼更簡單 - 但至少它避免了寫not in access
兩次。
我認爲你回答自己的問題有一些方法:它真的值得嗎? – Julien
它似乎是如此unpythonic。 – suchtgott
're.search('= |'+ name +'[。]',access)是None'避免重複,但我認爲我的並不比你的更好。 –