PYTHON Standard Library MCQs

  1. Which module is used for mathematical functions?
    a) math
    b) random
    c) statistics
    d) os
    View Answer

    Correct answer: A — math

  2. What will be printed?
    1 python
    2 import math
    3 print(math.sqrt(16))
    a) 4.0
    b) 16
    c) Error
    d) None
    View Answer

    Correct answer: A — 4.0

  3. Which module is used for generating random numbers?
    a) random
    b) math
    c) os
    d) sys
    View Answer

    Correct answer: A — random

  4. What is the output of print(random.randint(1,3))?
    a) 1,2 or 3
    b) 1 only
    c) Error
    d) None
    View Answer

    Correct answer: A — 1,2 or 3

  5. Which module is used for handling operating system tasks?
    a) os
    b) sys
    c) subprocess
    d) shutil
    View Answer

    Correct answer: A — os

  6. What will be printed?
    1 python
    2 import os
    3 print(os.name)
    a) posix or nt
    b) os
    c) Error
    d) None
    View Answer

    Correct answer: A — posix or nt

  7. Which module is used for system specific parameters?
    a) sys
    b) os
    c) platform
    d) subprocess
    View Answer

    Correct answer: A — sys

  8. What is the output of print(sys.version.split()[0])?
    a) Python version number
    b) sys
    c) Error
    d) None
    View Answer

    Correct answer: A — Python version number

  9. Which module is used for date and time manipulation?
    a) datetime
    b) time
    c) calendar
    d) os
    View Answer

    Correct answer: A — datetime

  10. What will be printed?
    1 python
    2 import datetime
    3 print(datetime.date.today().year)
    a) Current year
    b) Current month
    c) Error
    d) None
    View Answer

    Correct answer: A — Current year

  11. Which module is used for time related functions?
    a) time
    b) datetime
    c) calendar
    d) os
    View Answer

    Correct answer: A — time

  12. What is the output of print(time.sleep(1))?
    a) None
    b) 1
    c) Error
    d) sleep
    View Answer

    Correct answer: A — None

  13. Which module is used for calendar operations?
    a) calendar
    b) datetime
    c) time
    d) os
    View Answer

    Correct answer: A — calendar

  14. What will be printed?
    1 python
    2 import calendar
    3 print(calendar.isleap(2024))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  15. Which module is used for collections like Counter?
    a) collections
    b) itertools
    c) functools
    d) array
    View Answer

    Correct answer: A — collections

  16. What is the output of below code?
    1 python
    2 from collections import Counter
    3 print(Counter("Eduinq"))
    a) Counter({'E':1,'d':1,'u':1,'i':1,'n':1,'q':1})
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — Counter({'E':1,'d':1,'u':1,'i':1,'n':1,'q':1})

  17. Which module is used for functional programming tools?
    a) functools
    b) itertools
    c) collections
    d) operator
    View Answer

    Correct answer: A — functools

  18. What will be printed?
    1 python
    2 from functools import reduce
    3 print(reduce(lambda x,y:x+y,[1,2,3]))
    a) 6
    b) 123
    c) Error
    d) None
    View Answer

    Correct answer: A — 6

  19. Which module is used for iterator building blocks?
    a) itertools
    b) functools
    c) collections
    d) operator
    View Answer

    Correct answer: A — itertools

  20. What is the output of print(list(itertools.permutations([1,2],2)))?
    a) [(1,2),(2,1)]
    b) [(1,2)]
    c) Error
    d) None
    View Answer

    Correct answer: A — [(1,2),(2,1)]

  21. Which module is used for high performance array operations?
    a) array
    b) list
    c) collections
    d) numpy
    View Answer

    Correct answer: A — array

  22. What will be printed?
    1 python
    2 import array
    3 a = array.array('i',[1,2,3])
    4 print(a[1])
    a) 2
    b) 1
    c) 3
    d) Error
    View Answer

    Correct answer: A — 2

  23. Which module is used for file pattern matching?
    a) glob
    b) os
    c) fnmatch
    d) shutil
    View Answer

    Correct answer: A — glob

  24. What is the output of print(glob.glob("*.py"))?
    a) List of Python files
    b) *.py
    c) Error
    d) None
    View Answer

    Correct answer: A — List of Python files

  25. Which module is used for file operations like copy?
    a) shutil
    b) os
    c) sys
    d) subprocess
    View Answer

    Correct answer: A — shutil

  26. What will be printed?
    1 python
    2 import shutil
    3 print(hasattr(shutil,"copy"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  27. Which module is used for subprocess management?
    a) subprocess
    b) os
    c) sys
    d) shutil
    View Answer

    Correct answer: A — subprocess

  28. What is the output of below code?
    1 python
    2 import subprocess
    3 print(type(subprocess.run(["echo","Eduinq"])))
    a) CompletedProcess
    b) str
    c) Error
    d) None
    View Answer

    Correct answer: A — CompletedProcess

  29. Which module is used for JSON operations?
    a) json
    b) pickle
    c) marshal
    d) csv
    View Answer

    Correct answer: A — json

  30. What will be printed?
    1 python
    2 import json
    3 print(json.dumps({"Eduinq":1}))
    a) {"Eduinq":1}
    b) Eduinq:1
    c) Error
    d) None
    View Answer

    Correct answer: A — {"Eduinq":1}

  31. Which module is used for CSV operations?
    a) csv
    b) json
    c) pickle
    d) marshal
    View Answer

    Correct answer: A — csv

  32. What is the output of below code?
    1 python
    2 import csv
    3 print(hasattr(csv,"reader"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  33. Which module is used for XML parsing?
    a) xml.etree.ElementTree
    b) json
    c) csv
    d) marshal
    View Answer

    Correct answer: A — xml.etree.ElementTree

  34. What will be printed?
    1 python
    2 import xml.etree.ElementTree as ET
    3 root = ET.Element("Eduinq")
    4 print(root.tag)
    a) Eduinq
    b) tag
    c) Error
    d) None
    View Answer

    Correct answer: A — Eduinq

  35. Which module is used for serialization?
    a) pickle
    b) json
    c) csv
    d) marshal
    View Answer

    Correct answer: A — pickle

  36. What is the output of below code?
    1 python
    2 import pickle
    3 print(hasattr(pickle,"dump"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  37. Which module is used for compression?
    a) zlib
    b) gzip
    c) bz2
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  38. What will be printed?
    1 python
    2 import gzip
    3 print(hasattr(gzip,"open"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  39. Which module is used for hashing?
    a) hashlib
    b) hmac
    c) crypt
    d) os
    View Answer

    Correct answer: A — hashlib

  40. What is the output of below code?
    1 python
    2 import hashlib
    3 print(hashlib.md5(b"Eduinq").hexdigest())
    a) MD5 hash string
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — MD5 hash string

  41. Which module is used for regular expressions?
    a) re
    b) regex
    c) regexp
    d) None
    View Answer

    Correct answer: A — re

  42. What will be printed?
    1 python
    2 import re
    3 print(re.search("Edu","Eduinq").group())
    a) Edu
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — Edu

  43. Which module is used for decimal arithmetic?
    a) decimal
    b) fractions
    c) math
    d) statistics
    View Answer

    Correct answer: A — decimal

  44. What is the output of below code?
    1 python
    2 from decimal import Decimal
    3 print(Decimal('0.1')+Decimal('0.2'))
    a) 0.3
    b) 0.30000000000000004
    c) Error
    d) None
    View Answer

    Correct answer: A — 0.3

  45. Which module is used for fractions?
    a) fractions
    b) decimal
    c) math
    d) statistics
    View Answer

    Correct answer: A — fractions

  46. What will be printed?
    1 python
    2 from fractions import Fraction
    3 print(Fraction(1,3)+Fraction(1,6))
    a) 1/2
    b) 2/3
    c) Error
    d) None
    View Answer

    Correct answer: A — 1/2

  47. Which module is used for statistics?
    a) statistics
    b) math
    c) decimal
    d) fractions
    View Answer

    Correct answer: A — statistics

  48. What is the output of below code?
    1 python
    2 import statistics
    3 print(statistics.mean([1,2,3]))
    a) 2
    b) 1
    c) 3
    d) Error
    View Answer

    Correct answer: A — 2

  49. Which module is used for random sampling?
    a) random
    b) statistics
    c) math
    d) os
    View Answer

    Correct answer: A — random

  50. What will be printed?
    1 python
    2 import random
    3 print(random.sample([1,2,3,4],2))
    a) Any 2 random elements
    b) [1,2]
    c) Error
    d) None
    View Answer

    Correct answer: A — Any 2 random elements

Quick Links to Explore