Bird
0
0

Consider this simplified DDD code snippet in Python:

medium📝 Analysis Q13 of 15
LLD - Advanced LLD Concepts
Consider this simplified DDD code snippet in Python:
class Order:
    def __init__(self, order_id, items):
        self.order_id = order_id
        self.items = items

order1 = Order(1, ['apple', 'banana'])
order2 = Order(1, ['apple', 'banana'])

print(order1 == order2)

What will be the output?
ATrue
BFalse
CSyntaxError
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand default equality in Python classes

    By default, Python compares object references, so two different instances with same data are not equal.
  2. Step 2: Analyze the code output

    order1 and order2 are different objects with same data, so order1 == order2 returns False.
  3. Final Answer:

    False -> Option B
  4. Quick Check:

    Default object equality compares references = False [OK]
Quick Trick: Default == compares object identity, not data [OK]
Common Mistakes:
  • Assuming == compares data automatically
  • Expecting True because attributes match
  • Confusing syntax error with logic error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes