โ† All PCEP Flashcard Decks

Operator Precedence and Binding Flashcards

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

Read the first 7 Operator Precedence and Binding flashcards as text
  1. What is `6 % 4 + 1` equal to?

    Answer: 3

    Modulo `%` has the same precedence as `*` and `/`, so `6%4=2` first, then `2+1=3`.

  2. Which binding direction does the `**` operator use in Python?

    Answer: Right

    The exponentiation operator `**` is right-associative (right-binding), meaning `2**3**2` equals `2**(3**2)`.

  3. What does `False or 0 or '' or 'hello'` evaluate to?

    Answer: 'hello'

    `or` returns the first truthy value it finds; `False`, `0`, and `''` are all falsy, so `'hello'` is returned.

  4. What is the result of `not (True and False)`?

    Answer: True

    `True and False` evaluates to False inside parentheses, then `not False` equals True.

  5. In `x = 2 + 3 == 5`, what is the value of `x`?

    Answer: True

    Arithmetic has higher precedence than comparison: `2+3=5` first, then `5==5` equals True, assigned to x.

  6. What does `True and True or False and False` evaluate to?

    Answer: True

    `and` has higher precedence than `or`: `(True and True)=True` and `(False and False)=False`, then `True or False = True`.

  7. What is the result of `3 + 4j` in Python (assuming `j` is not defined)?

    Answer: NameError

    `j` without a preceding number is treated as an identifier, and since it's undefined, Python raises a NameError.