โ† All Python Flashcard Decks

Control Flow: Conditional Statements Flashcards

7 cards from real Python practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Control Flow: Conditional Statements flashcards as text
  1. What is the output of the following nested conditional? x, y = 3, 7 if x 5: print('A') else: print('B') else: print('C')

    Answer: A

    Both `x 5` are True, so the innermost branch prints 'A'.

  2. What will this print? num = 0 if num: print(num) else: print('zero')

    Answer: zero

    0 is falsy, so the else branch runs and prints 'zero'.

  3. Which statement about Python's `match` statement (Python 3.10+) is TRUE?

    Answer: It provides structural pattern matching similar to switch in other languages

    Python 3.10 introduced `match`/`case` for structural pattern matching, which can replace complex if/elif chains.

  4. What is the output? x = 5 result = 'big' if x > 10 else 'medium' if x > 3 else 'small' print(result)

    Answer: medium

    x > 10 is False, so the first else is evaluated; x > 3 is True, so 'medium' is returned.

  5. What is the correct way to check if a key exists in a dictionary before using it in an if statement?

    Answer: if key in dict:

    The `in` operator checks for key membership in a dictionary in Python.

  6. What does the following code print? a, b = True, False if a and not b: print('X') else: print('Y')

    Answer: X

    `a` is True and `not b` is True, so `a and not b` is True and 'X' is printed.

  7. In Python, which of the following values is considered TRUTHY?

    Answer: "0"

    A non-empty string like "0" is truthy; 0, empty list [], and empty string "" are all falsy.