Basic Difficult Python Quiz for New Learners

This quiz is designed to challenge new Python programmers by testing their understanding of the language beyond basic syntax. It covers advanced topics and tricky concepts such as mutable and immutable data types, default argument behavior, list comprehensions, OOP principles, generator expressions, and lambda functions. Each question will require careful reading and a deep understanding.

Python Fundamental Quiz 10

1 / 10

What is the output of the following code?

class A:
def __init__(self):
self.x = 1

class B(A):
pass

b = B()
print(b.x)

2 / 10

Which of the following statements about Python @staticmethod is false?

3 / 10

Which of the following is true about Python sets?

4 / 10

What does the following code return?

def foo(x=[]):
return len(x)

print(foo())

5 / 10

What does the following code do?

from functools import reduce
reduce(lambda x, y: x + y, [1, 2, 3, 4])

6 / 10

What is the result of the following code?

def foo():
yield 1
return 2

g = foo()
print(next(g))
print(next(g))

7 / 10

What will the following code output?

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

print(f(1))
print(f(2))

8 / 10

Which of the following functions is used to import a module dynamically in Python?

9 / 10

What is the result of the following code?

print(list(map(lambda x: x**2, [1, 2, 3, 4])))

10 / 10

What is the output of the following code?

x = [1, 2, 3]
print(x[1])

Your score is

The average score is 60%

0%

Leave a Reply