[Python] What is the difference between == and is in Python? [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am working with Python and noticed a strange behavior when comparing two lists. For example:


    a = [1, 2, 3]
    b = [1, 2, 3]
    print(a == b) # True
    print(a is b) # False
    ​

    Why does a == b return True, but a **is b return False? What is the difference between == and is? When should each be used?

    Continue reading...

Compartilhe esta Página