Python From Beginner to Advanced

0% completed

Previous
Next
Quiz
What does the Counter class in the collections module do?
A
Counts hashable objects
B
Implements high-performance data structures
C
Encodes data into JSON format
D
Manages database connections
Which function in the itertools module generates a sequence of integers?
A
chain()
B
cycle()
C
count()
D
compress()
What is a decorator in Python?
A
A function that modifies the functionality of another function
B
A tool to manage software packages
C
A type of Python data structure
D
A module for handling date and time operations
Given the following Python code, what will be the output?
from collections import Counter
fruit_count = Counter(['apple', 'orange', 'banana', 'apple', 'orange', 'apple'])
print(fruit_count['apple'])
A
1
B
2
C
3
D
4
Analyze the following code snippet. What does it demonstrate using the defaultdict class from the collections module?
from collections import defaultdict
dd = defaultdict(int)
dd['key1'] += 1
print(dd['key1'])
A
Demonstrating a syntax error because 'key1' is not explicitly set.
B
Using defaultdict to handle missing keys by providing a default value of 0.
C
The code fails because integers cannot be incremented using +=.
D
defaultdict is incorrectly applied, as it does not accept integer arguments.
Which of the following statements is true about decorators?
A
Decorators can only be applied to functions, not methods.
B
Decorators obfuscate the original function's docstring unless handled explicitly.
C
Once a function is decorated, it cannot be undecorated.
D
Decorators are executed at compile-time.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next