QuestenaPráctica que te muestra qué repasar después
Pregunta 118

Spot the identity-comparison pitfall: which warning is sound when two integers or strings should be compared by value?

  1. Equal literals are guaranteed to be one object.
  2. Identity is not a dependable general value comparison.Respuesta correcta
  3. Current CPython makes identity stable for every value.
  4. Identity first converts both operands to a common type.

Explicación

Object reuse and interning can vary by value and execution context, so equal integers or strings are not guaranteed to share identity. Apparent success in one run is therefore not a stable contract for value comparison.

Continúa con este test

Empezar la práctica
Pregunta 118: Spot the identity-comparison pitfall: which warning is… · Python Fundamentals · Questena