โ† 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 does the walrus operator `:=` do in Python?

    Answer: Assigns a value and returns it in the same expression

    The walrus operator `:=` (assignment expression) assigns a value to a variable and simultaneously returns that value within an expression.

  2. What is the result of `0.1 + 0.2 == 0.3` in Python?

    Answer: False

    Due to floating-point representation errors, `0.1 + 0.2` evaluates to `0.30000000000000004`, which is not equal to `0.3`.

  3. What does `x **= 2` do when `x = 3`?

    Answer: Sets x to 9

    `**=` is the in-place exponentiation operator, so `x **= 2` is equivalent to `x = x ** 2`, giving `3 ** 2 = 9`.

  4. What is the value of `bool(0) or bool(1)`?

    Answer: True

    `bool(0)` is `False` and `bool(1)` is `True`; `False or True` evaluates to `True`.

  5. What does the expression `'abc' * 3` evaluate to?

    Answer: 'abcabcabc'

    The `*` operator with a string and integer repeats the string that many times, producing `'abcabcabc'`.

  6. Which operator checks identity (same object in memory) in Python?

    Answer: is

    The `is` operator checks whether two variables point to the exact same object in memory, unlike `==` which checks value equality.

  7. What is the result of `not not True`?

    Answer: True

    `not True` is `False`, and `not False` is `True`, so double negation returns the original value.