How Well Do You Know Python?
Quizz Master [Discord]
Created 6/14/2024
Put your Python knowledge to the test and see how many correct answers you can get out of 15!
1. Which of the following functions is NOT part of the itertools module?
count()
cycle()
repeat()
map()
2. What does the itertools 'product()' function do?
Generates the Cartesian product of input iterables
Generates an infinite sequence of elements
Repeats an element infinitely
Accumulates sums of elements from iterable
3. Which function from itertools would you use to repeatedly generate 'ABABAB...'?
count()
cycle()
repeat()
accumulate()
4. What does the lambda keyword in Python do?
Defines a small anonymous function
Creates a generator
Starts a multiline comment
Defines a named function
5. Which of these is the syntax for defining a lambda function?
lambda x: x + 1
def lambda(x): x + 1
lambda (x: x + 1)
def lambda x: x + 1
6. What is the purpose of the 're' module?
Regular expressions
Random number generation
Reading files
Handling dates and times
7. Which method from the 're' module would you use to find all non-overlapping matches of a pattern in a string?
search()
match()
findall()
sub()
8. Which one is NOT a magic method in Python?
__add__
__init__
__call__
__map__
9. What is threading primarily used for in Python?
Speeding up computation by parallel execution
Reading and writing network sockets
Managing memory allocation
Creating GUI applications
10. Which module must be imported to use Thread class in Python?
threading
multiprocessing
asyncio
concurrent
11. What is the main purpose of the 'map()' function?
To apply a function to all items in an iterable
To filter elements from an iterable
To accumulate the results of elements in an iterable
To repeat elements of an iterable
12. What will be the result of evaluating list(map(lambda x: x + 1, [1, 2, 3]))?
[2, 3, 4]
[1, 2, 3]
[0, 1, 2]
[3, 4, 5]
13. What kind of exception does the 'ZeroDivisionError' in Python handle?
Division of a number by zero
Accessing an undefined variable
Accessing a list out of its bounds
File not found error
14. Which method is called automatically when an instance of a class is created?
__str__
__init__
__add__
__repr__
15. What does the 'finally' block do in exception handling?
Executes code no matter what happens
Handles an exception if one is raised
Raises an exception
Ignores any exceptions