Bird
0
0

Given this code:

hard📝 Application Q9 of 15
Python - Operators and Expression Evaluation
Given this code:
def check_identity(a, b):
    return a is b

x = 1000
y = 1000
print(check_identity(x, y))

Why might the output be False even though x == y is True?
ABecause function returns wrong result
BBecause 'is' compares values, not objects
CBecause variables x and y are assigned incorrectly
DBecause integers above 256 are not cached and are different objects
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python integer caching limits

    Python caches integers from -5 to 256. Numbers outside this range are different objects even if values match.
  2. Step 2: Understand difference between 'is' and '=='

    is checks object identity, == checks value equality.
  3. Final Answer:

    Because integers above 256 are not cached and are different objects -> Option D
  4. Quick Check:

    Large ints not cached, so 'is' is False [OK]
Quick Trick: Large integers are different objects despite equal values [OK]
Common Mistakes:
MISTAKES
  • Thinking 'is' compares values
  • Assuming all integers are cached
  • Believing function returns wrong result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes