Python Quizz

Home Python Quiz

Python Quizz

Dive into our tech quiz zone and put your technical skills to the test! Our quizzes cover a wide array of technical topics, perfect for sharpening your knowledge and challenging your understanding. Compete with others, see your rankings, and boost your technical proficiency. Start quizzing today!

1 / 70

1. What is the output of the following code?
def func(x):
return lambda y: x + y

f = func(10)
print(f(5))

2 / 70

2. 56. What will be the output of the following code?
class A:
def __init__(self, x):
self.x = x

def __str__(self):
return f'Value: {self.x}'

obj = A(10)
print(obj)

3 / 70

3. What will be the output of the following code?
import weakref

class A:
pass

a = A()
r = weakref.ref(a)
print(r())
del a
print(r())

4 / 70

4. What will be the output of the following code?
import re

pattern = re.compile(r'\d+')
result = pattern.findall('My number is 123 and my friend's number is 456')
print(result)

5 / 70

5. What will be the output of the following code?
import re

pattern = re.compile(r'\d+')
result = pattern.sub('#', 'My number is 123 and my friend's number is 456')
print(result)

6 / 70

6. What will be the output of the following code?
class A:
def __init__(self, x):
self.x = x

def __add__(self, other):
return A(self.x + other.x)

obj1 = A(1)
obj2 = A(2)
obj3 = obj1 + obj2
print(obj3.x)

7 / 70

7. Which of the following is true about coroutines in Python?

8 / 70

8. What is the purpose of the @functools.wraps decorator in Python?

9 / 70

9. Which of the following is true about Python inheritance?

10 / 70

10. What does the following code do?

class C:
def __init__(self, x):
self.x = x

def __call__(self, y):
return self.x + y

obj = C(10)
print(obj(5))

11 / 70

11. What will be the output of the following code?
import logging

logging.basicConfig(level=logging.INFO)
logging.debug('Debug message')
logging.info('Info message')
logging.warning('Warning message')

12 / 70

12. What is the purpose of the await keyword in Python?

13 / 70

13. What is the result of the following code?

class A:
def __init__(self):
self.a = 1
self.__b = 2

class B(A):
def __init__(self):
super().__init__()
self.a = 3
self.__b = 4

obj = B()
print(obj.a)
print(obj._A__b)

14 / 70

14. What is the purpose of the nonlocal keyword in Python?

15 / 70

15. Which of the following is true about Python's garbage collector?

16 / 70

16. What is the purpose of the partial function in the functools module?

17 / 70

17. What is the purpose of the __new__ method in a Python class?

18 / 70

18. What is the output of the following code?

a = [1, 2, 3]
b = a
a = a + [4, 5]
print(b)

19 / 70

19. What will be the output of the following code?
def generator_func():
yield 1
yield 2
yield 3

g = generator_func()
print(next(g))
print(next(g))
print(next(g))
print(next(g))

20 / 70

20. What is the purpose of the GIL (Global Interpreter Lock) in Python?

21 / 70

21. Which method in the os module is used to change the current working directory?

22 / 70

22. Which module is used to handle date and time in Python?

23 / 70

23. What will be the output of the following code?
import pdb

def test():
pdb.set_trace()
print("Hello, World!")

test()

24 / 70

24. Which method is used to read all lines of a file into a list?

25 / 70

25. What will be the output of the following code?
import multiprocessing

def print_numbers():
for i in range(5):
print(i)

p1 = multiprocessing.Process(target=print_numbers)
p2 = multiprocessing.Process(target=print_numbers)

p1.start()
p2.start()

p1.join()
p2.join()

26 / 70

26. What will be the output of the following code?
with open('test.txt', 'w') as f:
f.write('Hello, World!')

with open('test.txt', 'rb') as f:
print(f.read())

27 / 70

27. What is the purpose of the __del__ method in a Python class?

28 / 70

28. Which method is used to dynamically create a class in Python?

29 / 70

29. Which module is used for debugging in Python?

30 / 70

30. What is the output of the following code?
from collections import deque

d = deque([1, 2, 3, 4])
d.appendleft(0)
d.pop()
d.extend([5, 6])
d.rotate(1)
print(d)

31 / 70

31. What does the __getattr__ method do in a Python class?

32 / 70

32. Which of the following is a Python memory management technique?

33 / 70

33. What is the purpose of the set_trace method in the pdb module?

34 / 70

34. What does the following code do?
from contextlib import contextmanager

@contextmanager
def open_file(name):
f = open(name, 'w')
try:
yield f
finally:
f.close()

with open_file('test.txt') as f:
f.write('Hello, World!')

35 / 70

35. What will be the output of the following code?
import threading

def print_numbers():
for i in range(5):
print(i)

t1 = threading.Thread(target=print_numbers)
t2 = threading.Thread(target=print_numbers)

t1.start()
t2.start()

t1.join()
t2.join()

36 / 70

36. What will be the output of the following code?
import re

pattern = re.compile(r'(\d{3})-(\d{2})-(\d{4})')
match = pattern.match('123-45-6789')
print(match.groups())

37 / 70

37. What will be the output of the following code?
import sys

a = []
b = a
print(sys.getrefcount(a))

38 / 70

38. What is the purpose of the __call__ method in a Python class?

39 / 70

39. What will be the output of the following code?
import heapq

h = [3, 1, 4, 1, 5, 9, 2, 6]
heapq.heapify(h)
print([heapq.heappop(h) for _ in range(3)])

40 / 70

40. What will be the output of the following code?
with open('test.txt', 'w') as f:
f.write('Hello, World!')

with open('test.txt', 'r') as f:
print(f.read())

41 / 70

41. Which module is used to create and manage complex data structures in Python?

42 / 70

42. What will be the output of the following code?

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

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

43 / 70

43. What will be the output of the following code?
import unittest

class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')

if __name__ == '__main__':
unittest.main()

44 / 70

44. What will be the output of the following code?
class A:
pass

obj = A()
print(type(obj).__name__)

45 / 70

45. What will be the output of the following code?
def decorator_func(func):
def wrapper(*args, **kwargs):
print("Before")
result = func(*args, **kwargs)
print("After")
return result
return wrapper

@decorator_func
def say_hello():
print("Hello!")

say_hello()

46 / 70

46. What will be the output of the following code?
class A:
def __init__(self):
self.value = 42

obj = A()
print(getattr(obj, 'value'))

47 / 70

47. What will be the output of the following code?
from functools import reduce

result = reduce(lambda x, y: x + y, [1, 2, 3, 4, 5])
print(result)

48 / 70

48. What is the purpose of the tell method in file handling?

49 / 70

49. Which function is used to get the reference count of an object in Python?

50 / 70

50. What is the purpose of the __slots__ attribute in a Python class?

51 / 70

51. What will be the output of the following code?
from collections import defaultdict

d = defaultdict(int)
d['a'] += 1
d['b'] += 2
d['c'] += 3
print(d['a'], d['b'], d['c'], d['d'])

52 / 70

52. What will be the output of the following code?

def decorator_func(func):
def wrapper(*args, **kwargs):
print("Wrapper executed this before {}".format(func.__name__))
return func(*args, **kwargs)
return wrapper

@decorator_func
def display():
print("Display function ran")

display()

53 / 70

53. What does the yield from statement do in Python?

54 / 70

54. What will be the output of the following code?
from itertools import cycle

colors = ['red', 'green', 'blue']
cycle_colors = cycle(colors)
for _ in range(5):
print(next(cycle_colors))

55 / 70

55. Which module is used for asynchronous programming in Python?

56 / 70

56. What will be the output of the following code?

def func(x, y, z=3, *args, **kwargs):
return x + y + z + sum(args) + sum(kwargs.values())

print(func(1, 2, 3, 4, 5, a=6, b=7))

57 / 70

57. Which module is used for JSON manipulation in Python?

58 / 70

58. Which module is used for creating processes in Python?

59 / 70

59. Which method is used to read a specific number of bytes from a file?

60 / 70

60. Which method is used to convert a string to a frozenset?

61 / 70

61. Which of the following is true about lambda functions in Python?

62 / 70

62. What is the purpose of the gc module in Python?

63 / 70

63. Which method in the re module is used to search for a pattern in a string?

64 / 70

64. Which module is used for mocking in Python?

65 / 70

65. Which of the following is true about namedtuples?

66 / 70

66. Which of the following is true about context managers in Python?

67 / 70

67. What is the purpose of the seek method in file handling?

68 / 70

68. What is the purpose of the @patch decorator in the unittest.mock module?

69 / 70

69. Which method is used to replace all occurrences of a pattern in a string?

70 / 70

70. What will be the output of the following code?
import os

os.chdir('/tmp')
print(os.getcwd())

Your score is

0%