← 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: x = None if x: print('truthy') else: print('falsy')

    Answer: falsy

    None is falsy in Python, so the else branch executes and prints 'falsy'.

  2. Which of the following correctly checks if a variable `n` is between 1 and 10 inclusive?

    Answer: if 1 <= n <= 10:

    Python supports chained comparisons like `1 <= n <= 10`, which is the most Pythonic way.

  3. What does `pass` do inside an `if` block?

    Answer: Does nothing; acts as a placeholder

    `pass` is a no-op statement used as a syntactic placeholder when a block is required but no action is needed.

  4. What is the output? for i in range(3): if i == 1: pass else: print(i)

    Answer: 0 2

    When i==1 the `pass` does nothing and no print occurs, so only 0 and 2 are printed.

  5. Which of the following correctly uses `not` in an if statement?

    Answer: if not x == 5:

    `not` is Python's logical negation operator and `not x == 5` is valid syntax.

  6. What is printed? val = '' if val: print('has value') elif val is None: print('is None') else: print('empty')

    Answer: empty

    An empty string is falsy but not None, so neither the if nor the elif match, and 'empty' is printed.

  7. In Python, `if x is None:` differs from `if x == None:` because:

    Answer: `is` checks identity, while `==` checks equality

    `is` tests object identity (same object in memory), while `==` tests value equality; PEP 8 recommends `is None`.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy