[Python] Python `if x is not None` or `if not x is None`?

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    I've always thought of the if not x is None version to be more clear, but Google's style guide and PEP-8 both use if x is not None. Are there any minor performance differences (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?*

    *I'm referring to any singleton, rather than just None.


    ...to compare singletons like None. Use is or is not.
    ​

    Continue reading...

Compartilhe esta Página