Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 5 · Architecture & Code ReviewPattern matching internals — __match_args__predict76 / 161
+125 XP
Task
📝 **Question:** Predict the exact output. \`Point\` declares \`__match_args__ = ("x", "y")\`, so the positional form \`Point(x, y)\` in a case clause unpacks via those slots. Five inputs are passed through \`describe()\` — predict each return value. 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predict the output

Read the code carefully

class Point:
    __match_args__ = ("x", "y")
    def __init__(self, x, y):
        self.x = x
        self.y = y


def describe(p):
    match p:
        case Point(0, 0):
            return "origin"
        case Point(0, y):
            return f"y-axis:{y}"
        case Point(x, y) if x == y:
            return f"diag:{x}"
        case Point(x, y):
            return f"other:{x},{y}"
        case _:
            return "not_point"


print(describe(Point(0, 0)))
print(describe(Point(0, 5)))
print(describe(Point(3, 3)))
print(describe(Point(2, 7)))
print(describe("hello"))

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…