Python Libraries

Last Updated :
Discuss
Comments

Question 1

What does the heapq module in Python provide?


  • A

    Binary Search Tree implementation

  • B

    Priority Queue via heaps

  • C

    Balanced AVL Tree

  • D

    Linked List operations


Question 2

What will be the output of the following code?

Python
import heapq
nums = [4, 1, 3]
heapq.heapify(nums)
print(nums[0])



  • A

    4

  • B

    1

  • C

    3

  • D

    [1, 3, 4]

Question 3

What does heapq.heappush() do?


  • A

    Pops the largest element

  • B

    Pushes an element and maintains max-heap

  • C

    Inserts element and maintains min-heap

  • D

    Sorts the list in-place


Question 4

Which of the following is true about bisect.insort()?


  • A

    Appends item without sorting

  • B

    Inserts item while maintaining sorted order

  • C

    Randomly inserts item

  • D

    Removes item at index

Question 5

Which stream does sys.stderr represent?


  • A

    Standard input

  • B

    Standard output

  • C

    Standard error

  • D

    Debug log

Question 6

What will be the result of this code?

Python
import array
arr = array.array('i', [1, 2, 3])
arr.append(4)
print(arr.tolist())



  • A

    [1, 2, 3]

  • B

    [1, 2, 3, 4]

  • C

    [4, 3, 2, 1]

  • D

    Error due to type mismatch

Question 7

What will this output?

Python
import platform
print(platform.system())



  • A

    Python version

  • B

    OS name like 'Windows' or 'Linux'

  • C

    CPU name

  • D

     Hostname


Question 8

What will the following code print?

Python
import platform
print(platform.uname().node)


  • A

    CPU vendor

  • B

    System version

  • C

    Hostname

  • D

    Username

Question 9

What will this code output?

Python
import os
os.makedirs("dir1/dir2")


  • A

    Creates one directory only

  • B

    Raises an error

  • C

    Creates nested directories dir1 and dir2

  • D

    Deletes dir2 if exists

Question 10

What is the purpose of functools.partial()?

  • A

    Creates partial copies of data

  • B

    Fixes some function arguments ahead of time

  • C

    Delays execution

  • D

    Wraps functions in lambdas

There are 13 questions to complete.

Take a part in the ongoing discussion