Python Quiz for New Learners

This quiz will push you to think critically about how Python executes code and will help you solidify your foundational understanding of the language. While it may seem difficult, it is an excellent opportunity to identify gaps in your knowledge and practice solving problems like a Python expert. Good luck!

Python Fundamental Quiz 9

Python Quiz for New Learners

This quiz will push you to think critically about how Python executes code and will help you solidify your foundational understanding of the language. While it may seem difficult, it is an excellent opportunity to identify gaps in your knowledge and practice solving problems like a Python expert. Good luck!

 

1 / 10

What will be the output of this generator expression?

gen = (x**2 for x in range(5))
print(sum(gen))

2 / 10

Which statement is incorrect about Python's global and nonlocal keywords?

3 / 10

What is the output of the following code?

x = [1, 2, 3]
y = x[:]
x[0] = 100
print(y)

4 / 10

What does collections.defaultdict do?

 

5 / 10

What is the output of the following code?

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

class B(A):
def __init__(self):
super().__init__()
self.y = 2

a = A()
b = B()
print(a.x, b.x, b.y)

6 / 10

What does the following list comprehension do?

list_1 = [x for x in range(10) if x % 2 == 0]Creates a list of numbers from 0 to 10.Creates a list of numbers from 0 to 10.

7 / 10

Which of the following is true about Python's memory management?

 

8 / 10

What will be the output of the following code?

a = [1, 2, 3]
b = a
a.append(4)
print(b)

9 / 10

What will be the output of the following code?

def func(val, lst=[]):
lst.append(val)
return lst

print(func(1))
print(func(2))
print(func(3, []))
print(func(4))[1] [1, 2] [3] [1, 2, 4]

10 / 10

What will the following code output?

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

print(func(1))
print(func(2))

Your score is

The average score is 35%

0%

Leave a Reply