Python Programming - Standard Libraries

Exercise : Standard Libraries - General Questions
  • Standard Libraries - General Questions
61.
What is the purpose of the collections.namedtuple() function?
Creating named tuples with named fields
Sorting elements in a list
Handling dates and times
Parsing JSON data
Answer: Option
Explanation:
The collections.namedtuple() function in Python is used to create named tuples with named fields.

62.
Which module in Python provides functions for working with regular expressions in a more advanced and powerful manner than the re module?
regexlib
advancedre
relib
regex
Answer: Option
Explanation:
The regex module in Python provides functions for working with regular expressions in a more advanced and powerful manner than the re module.

63.
What does the multiprocessing module in Python provide?
Asynchronous I/O operations
Functions for working with multiprocessing
Generating random numbers
Sorting elements in a list
Answer: Option
Explanation:
The multiprocessing module in Python provides functions and classes for working with multiprocessing, allowing the execution of parallel processes.

64.
How can you use the collections.Counter class in Python to count the occurrences of elements in a list?
counter.count_elements()
collections.count()
Counter.count()
collections.Counter()
Answer: Option
Explanation:
from collections import Counter

# Example usage of collections.Counter
my_list = [1, 2, 3, 1, 2, 1, 4, 5, 4, 3, 2]
element_counts = Counter(my_list)
print(element_counts)

65.
Which module in Python provides support for working with regular expressions in a more advanced and powerful manner than the re module?
regexlib
advancedre
relib
regex
Answer: Option
Explanation:
import regex as re

# Example usage of regex module
pattern = re.compile(r'\b(\w+)\b')
text = "This is a sample text."
matches = pattern.findall(text)
print(matches)