Python · Structural Pattern Matching

What does this print? ``` _ = "keep" match "x": case _: print(_) ```

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Structural Pattern Matching

What does this print? ``` d = {"a": 1, "b": 2, "c": 3} match d: case {"a": 1}: print("match") case _: print("no") ```
What does this print? ``` match 5: case 1 | 2 | 3: print("low") case 4 | 5 | 6: print("mid") ```
What does this print? ``` match [1, 2]: case (1, 2): print("tuple pat") case [1, 2]: print("list pat") ```
What happens when you run this? ``` x = 0 match "hello": case x: print("matched") case "hello": print("literal") ```
You have a module constant MAX = 100. Why does this always match, printing "hit" even when n is 5? ``` match n: case MAX: print("hit") ```
What does this print? ``` from enum import Enum class C(Enum): RED = 1 BLUE = 2 match C.BLUE: case C.RED: print("red") case C.BLUE: print("blue") ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play