Exercise: Standard Libraries

Questions for: Standard Libraries

Which method is used to add an element to the end of a list?
A:
list.append()
B:
list.insert()
C:
list.extend()
D:
list.add()
Answer: A
The append() method is used to add an element to the end of a list in Python.
What does the itertools.cycle() function do?
A:
Creates an infinite iterator from a finite iterable
B:
Generates all possible permutations of an iterable
C:
Repeats an iterable indefinitely
D:
Filters elements based on a predicate function
Answer: C
The itertools.cycle() function in Python repeats an iterable indefinitely, cycling through its elements.
Which module in Python is used for working with network-related tasks, such as creating and handling sockets?
A:
network
B:
socketlib
C:
net
D:
socket
Answer: D
The socket module in Python is used for working with sockets, allowing you to create and handle network connections.
What is the purpose of the heapq module?
A:
Sorting elements in a list
B:
Implementing priority queues
C:
Working with regular expressions
D:
Handling dates and times
Answer: B
The heapq module in Python provides functions for implementing heap queues, which are often used to implement priority queues.
What is the purpose of the hashlib module?
A:
Mathematical operations
B:
File I/O operations
C:
Working with cryptographic hash functions
D:
Web development
Answer: C
The hashlib module in Python is used for working with cryptographic hash functions, providing a way to generate secure hash values.
Ad Slot (Above Pagination)
Quiz