Skip to content
CodeKruPro

Structural pattern matching with match

QuizMediumPython only

Given this function, which calls return the value shown? Pick all that apply.

def describe(cmd):
    match cmd:
        case "start" | "run":
            return "go"
        case ["move", x, y]:
            return f"move {x},{y}"
        case {"action": a}:
            return f"action {a}"
        case int(n) if n > 5:
            return "big int"
        case _:
            return "unknown"
  • describe("run") returns "go"
  • describe(["move", 1, 2]) returns "move 1,2"
  • describe({"action": "click", "x": 1}) returns "unknown"
  • describe(2) returns "big int"

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in