โ† All Python Flashcard Decks

Operators and Expressions 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 Operators and Expressions flashcards as text
  1. What is the result of `5 // -2` in Python?

    Answer: -3

    Floor division rounds toward negative infinity, so `5 // -2` is `-2.5` rounded down to `-3`.

  2. What does the bitwise XOR operator `^` return for `6 ^ 3`?

    Answer: 5

    `6` is `110` and `3` is `011` in binary; XOR gives `101`, which is `5`.

  3. What is the result of `[1, 2] + [3, 4]`?

    Answer: [1, 2, 3, 4]

    The `+` operator on lists performs concatenation, combining both lists into a single new list `[1, 2, 3, 4]`.

  4. What is the precedence order (highest to lowest) for these operators: `+`, `**`, `*`?

    Answer: **, *, +

    Python's operator precedence places `**` (exponentiation) highest, then `*` (multiplication), then `+` (addition).

  5. What does `x = 10; x &= 6` result in for `x`?

    Answer: 2

    `10` is `1010` and `6` is `0110` in binary; bitwise AND gives `0010`, which is `2`.

  6. What is the result of evaluating `3 2` in Python?

    Answer: True

    Python supports chained comparisons; `3 2` is evaluated as `3 2`, which is `True and True = True`.

  7. What is the result of `divmod(17, 5)`?

    Answer: (3, 2)

    `divmod(17, 5)` returns a tuple of `(quotient, remainder)`, which is `(3, 2)` since `17 = 5*3 + 2`.