Python Quiz

401. What will be the output of this code?

def func(a, b=[]):
    b.append(a)
    return b

print(func(1))
print(func(2))
402. What is the result of:

print([i for i in range(3)] == list(map(lambda x: x, range(3))))
403. What is the purpose of `__slots__` in Python classes?
404. What will this print?

def gen():
    yield 1
    yield 2
    return 3

print(list(gen()))
405. What is a key difference between `@staticmethod` and `@classmethod`?
406. What is the output of:

print({x for x in 'banana'})
407. Which of the following is **not** true about Python generators?
408. What does this output?

x = (i*i for i in range(3))
print(next(x), next(x))
409. How do you make a shallow copy of a list in Python?
410. What will this output?

x = [1, 2, 3]
y = x
x += [4]
print(x, y)

Explore Programming Topics