Question 71
HardWhat is the output of this program?
from functools import lru_cache
calls = 0
():
calls
calls +=
n n < fib(n - ) + fib(n - )
(fib(), calls)
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this program?
from functools import lru_cache
calls = 0
():
calls
calls +=
n n < fib(n - ) + fib(n - )
(fib(), calls)
514229 31
832040 31
832040 1664079
832040 30
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
print(sorted({3: "c", 1: "a", 2: "b"}.items(), key=lambda kv: kv[1], reverse=True), max("apple", "Banana", key=str.lower))
[(3, 'c'), (2, 'b'), (1, 'a')] apple
[(1, 'a'), (2, 'b'), (3, 'c')] apple
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
x = [1, 2, 3]
y = x
x = x + [4]
z = y
z += [5]
print(x, y)
[1, 2, 3, 4] [1, 2, 3]
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
Sign up free to see the answer and a step-by-step explanation.
What does Python's 'is' operator return for two equal small integers such as 256 created separately, and why is relying on it wrong?
It raises an error
Always False
Often True because CPython caches small integers, but that is an implementation detail; use == for values
It compares values
Sign up free to see the answer and a step-by-step explanation.
What does the GIL mean for a CPU-bound program using threads in CPython?
Threads run fully in parallel
It only affects I/O
Only one thread runs Python bytecode at a time, so threads don't speed it up; use multiprocessing
Threads are disabled
Sign up free to see the answer and a step-by-step explanation.
What is a Python descriptor?
An object with get / set that controls attribute access, as used by property and methods
A type hint
A file handle
A decorator only
Sign up free to see the answer and a step-by-step explanation.
What does @dataclass generate for a class?
init, repr and eq (and more on request) from the annotated fields
Only init
Nothing
A database table
Sign up free to see the answer and a step-by-step explanation.
What is the difference between a list comprehension and a generator expression in memory use?
They are identical
List comprehensions are lazy
Generators use more memory
A list comprehension builds the whole list; a generator produces items one at a time
Sign up free to see the answer and a step-by-step explanation.
What does 'async def' together with 'await' give in Python?
True parallelism on many cores
Automatic threading
Faster CPU-bound code
Cooperative concurrency on one thread, switching tasks at await points
Sign up free to see the answer and a step-by-step explanation.
Why does modifying a dictionary while iterating over it raise RuntimeError?
Keys must be strings
It doesn't
Dictionaries are read-only
Changing its size invalidates the iteration order
Sign up free to see the answer and a step-by-step explanation.
[(3, 'c'), (1, 'a'), (2, 'b')] Banana
[(3, 'c'), (2, 'b'), (1, 'a')] Banana
[1, 2, 3, 4] [1, 2, 3, 5]
[1, 2, 3, 4, 5] [1, 2, 3, 5]