CARVIEW |
Python Libraries
This quiz checks what you know about Python libraries. They help make coding quicker and easier!
Question 1
What does the heapq module in Python provide?
Binary Search Tree implementation
Priority Queue via heaps
Balanced AVL Tree
Linked List operations
Question 2
What will be the output of the following code?
import heapq
nums = [4, 1, 3]
heapq.heapify(nums)
print(nums[0])
4
1
3
[1, 3, 4]
Question 3
What does heapq.heappush() do?
Pops the largest element
Pushes an element and maintains max-heap
Inserts element and maintains min-heap
Sorts the list in-place
Question 4
Which of the following is true about bisect.insort()?
Appends item without sorting
Inserts item while maintaining sorted order
Randomly inserts item
Removes item at index
Question 5
Which stream does sys.stderr represent?
Standard input
Standard output
Standard error
Debug log
Question 6
What will be the result of this code?
import array
arr = array.array('i', [1, 2, 3])
arr.append(4)
print(arr.tolist())
[1, 2, 3]
[1, 2, 3, 4]
[4, 3, 2, 1]
Error due to type mismatch
Question 7
What will this output?
import platform
print(platform.system())
Python version
OS name like 'Windows' or 'Linux'
CPU name
Hostname
Question 8
What will the following code print?
import platform
print(platform.uname().node)
CPU vendor
System version
Hostname
Username
Question 9
What will this code output?
import os
os.makedirs("dir1/dir2")
Creates one directory only
Raises an error
Creates nested directories dir1 and dir2
Deletes dir2 if exists
Question 10
What is the purpose of functools.partial()?
Creates partial copies of data
Fixes some function arguments ahead of time
Delays execution
Wraps functions in lambdas
There are 13 questions to complete.