[Python] Why does comparing strings using either '==' or 'is' sometimes produce a different...

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    Two string variables are set to the same value. s1 == s2 always returns True, but s1 is s2 sometimes returns False.

    If I open my Python interpreter and do the same is comparison, it succeeds:

    >>> s1 = 'text'
    >>> s2 = 'text'
    >>> s1 is s2
    True


    Why is this?

    Continue reading...

Compartilhe esta Página