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
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`.
What does `5 | 3` evaluate to?
Answer: 7
Bitwise OR: `101 | 011` = `111` = `7`.
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.
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`.
What does `3 << 2` evaluate to?
Answer: 12
Left shift by 2 multiplies by `2²`; `3 * 4 = 12`.
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.
What is the output of `isinstance(True, int)`?
Answer: True
`bool` is a subclass of `int` in Python, so `isinstance(True, int)` returns `True`.