Python Basics 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 Python Basics flashcards as text
What does the `//` operator do in Python?
Answer: Floor division (integer quotient)
The `//` operator performs floor division, truncating the result toward negative infinity.
Which of the following correctly unpacks a tuple `t = (1, 2, 3)` into three variables?
Answer: a, b, c = t
Tuple unpacking assigns each element to a corresponding variable with `a, b, c = t`.
What is the output of `bool([])` in Python?
Answer: False
An empty list is falsy in Python, so `bool([])` returns `False`.
Which built-in function returns the number of elements in a list?
Answer: len()
`len()` is the built-in function that returns the number of items in a sequence or collection.
What will `'hello'[1:4]` evaluate to?
Answer: 'ell'
Slicing `[1:4]` extracts characters at indices 1, 2, and 3, yielding `'ell'`.
How do you convert the string `'42'` to an integer in Python?
Answer: int('42')
The built-in `int()` function converts a numeric string to an integer.
What is the result of `3 ** 2` in Python?
Answer: 9
The `**` operator is Python's exponentiation operator, so `3 ** 2` equals 9.