← All HACKERRANK Flashcard Decks

Scalar Types and Operators Flashcards

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

Read the first 7 Scalar Types and Operators flashcards as text
  1. What is the result of `5 & 3` in Python?

    Answer: 1

    Bitwise AND: `5` is `101` and `3` is `011`; AND gives `001` which equals `1`.

  2. What does `5 | 3` evaluate to?

    Answer: 7

    Bitwise OR: `101 | 011` = `111` = `7`.

  3. Which expression correctly checks if `x` is between 1 and 10 inclusive in Python?

    Answer: All of the above

    All three forms are valid Python; the chained comparison `1 <= x <= 10` is syntactic sugar for the explicit `and` form.

  4. What is the result of `~5` in Python?

    Answer: -6

    The bitwise NOT `~n` returns `-(n + 1)` in Python due to two's complement representation; `~5 = -6`.

  5. What does `3 << 2` evaluate to?

    Answer: 12

    Left shift by 2 multiplies by `2²`; `3 * 4 = 12`.

  6. What is the type of the result of dividing two integers with `/` in Python 3?

    Answer: float

    In Python 3, the `/` operator always returns a `float` even when both operands are integers.

  7. What is the output of `isinstance(True, int)`?

    Answer: True

    `bool` is a subclass of `int` in Python, so `isinstance(True, int)` returns `True`.