Question 41
MediumWhat is the output of this program?
def gen():
for i ():
i *
g = gen()
((g), (g), (g), (g))
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?
def gen():
for i ():
i *
g = gen()
((g), (g), (g), (g))
0 0 [20] [20]
0 10 [20] [20]
0 10 [20] []
0 10 [0, 10, 20] []
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
print(sorted(["banana", "Apple", "cherry", "date"], key=lambda w: (len(w), w.lower())))
['date', 'Apple', 'cherry', 'banana']
['Apple', 'banana', 'cherry', 'date']
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
t = (1, [2, 3])
t[1].append(4)
print(t, len(t))
(1, [2, 3, 4]) 3
(1, [2, 3]) 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 2) == 0.3, 7 // -2, -7 % 3)
True True -3 -1
False True -4 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
from collections import Counter
c = Counter("mississippi")
print(c.most_common(2), c["z"])
[('i', 4), ('p', 2)] 0
[('s', 4), ('i', 4)] 0
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
a = [3, 1, 2]
b = sorted(a)
a.sort(reverse=True)
print(a, b, a.sort())
[1, 2, 3] [1, 2, 3] None
[3, 1, 2] [1, 2, 3] None
Sign up free to see the answer and a step-by-step explanation.
What is the difference between a list and a tuple in Python?
There is no difference
Lists are mutable; tuples are immutable (and can be dictionary keys if their items are hashable)
Tuples are faster to append to
Lists can't hold mixed types
Sign up free to see the answer and a step-by-step explanation.
What does the Global Interpreter Lock (GIL) in CPython mean for threads?
Only one thread runs Python bytecode at a time, so CPU-bound threads don't run in parallel
It locks global variables only
Threads always run in parallel
Threads cannot be created
Sign up free to see the answer and a step-by-step explanation.
What is a decorator in Python?
A type hint
A comment syntax
A function that takes a function and returns a new function that adds behaviour
A class attribute
Sign up free to see the answer and a step-by-step explanation.
What does 'is' compare, as opposed to '=='?
Whether two types are equal
Nothing; they are the same
Whether two names refer to the same object
Whether two values are equal
Sign up free to see the answer and a step-by-step explanation.
['Apple', 'date', 'banana', 'cherry']
['date', 'Apple', 'banana', 'cherry']
(1, [2, 3, 4]) 2
TypeError
False False -4 2
False True -3 2
[('i', 4), ('s', 4)] KeyError
[('i', 4), ('s', 4)] 0
[3, 2, 1] [1, 2, 3] [1, 2, 3]
[3, 2, 1] [1, 2, 3] None