What's more efficient in Python: `key not in list` or `not key in list`? [duplicate]
问题 This question already has answers here : “x not in y” or “not x in y” (6 answers) Closed 2 years ago . Just found out that both syntax ways are valid. Which is more efficient? element not in list Or: not element in list ? 回答1: They behave identically, to the point of producing identical byte code; they're equally efficient. That said, element not in list is usually considered preferred. PEP8 doesn't have a specific recommendation on not ... in vs. ... not in , but it does for not ... is vs. .