PYTHON Modules and Packages MCQs

  1. Which keyword is used to import a module in Python?
    a) include
    b) import
    c) using
    d) require
    View Answer

    Correct answer: B — import

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

    Correct answer: A — 4

  3. Which of the following is used to import specific function from module?
    a) import module.function
    b) from module import function
    c) using module.function
    d) require module.function
    View Answer

    Correct answer: B — from module import function

  4. What is the output of print(math.pi)?
    a) 3.14
    b) 3.141592653589793
    c) Error
    d) None
    View Answer

    Correct answer: B — 3.141592653589793

  5. Which of the following is used to import module with alias?
    a) import module as alias
    b) import alias module
    c) using module alias
    d) require module alias
    View Answer

    Correct answer: A — import module as alias

  6. What will be printed?
    1 import random
    2 print(random.randint(1,3))
    a) 1
    b) 2
    c) 3
    d) Any of the above
    View Answer

    Correct answer: D — Any of the above

  7. Which of the following is used to import all functions from module?
    a) import *
    b) from module import *
    c) using *
    d) require *
    View Answer

    Correct answer: B — from module import *

  8. What is the output of print(len(dir(math)))?
    a) Number of attributes in math module
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Number of attributes in math module

  9. Which of the following is used to reload a module?
    a) reload(module)
    b) importlib.reload(module)
    c) reimport(module)
    d) require(module)
    View Answer

    Correct answer: B — importlib.reload(module)

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

    Correct answer: A — posix or nt

  11. Which of the following is used to get current working directory?
    a) os.getcwd()
    b) os.get()
    c) os.dir()
    d) os.path()
    View Answer

    Correct answer: A — os.getcwd()

  12. What is the output of print(sys.version)?
    a) Python version string
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Python version string

  13. Which of the following is used to exit program?
    a) sys.exit()
    b) os.exit()
    c) exit()
    d) Both A and C
    View Answer

    Correct answer: D — Both A and C

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

    Correct answer: A — Current year

  15. Which of the following is used to import JSON module?
    a) import json
    b) import JSON
    c) using json
    d) require json
    View Answer

    Correct answer: A — import json

  16. What is the output of print(json.dumps({"Eduinq":1}))?
    a) {"Eduinq":1}
    b) Eduinq:1
    c) Error
    d) None
    View Answer

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

  17. Which of the following is used to import CSV module?
    a) import csv
    b) import CSV
    c) using csv
    d) require csv
    View Answer

    Correct answer: A — import csv

  18. What will be printed?
    1 import csv
    2 print(type(csv))
    a) <class 'module'>
    b) <class 'dict'>
    c) <class 'list'>
    d) Error
    View Answer

    Correct answer: A — <class 'module'>

  19. Which of the following is used to import custom module?
    a) import filename
    b) from filename import *
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  20. What is the output of print(__name__)?
    a) __main__
    b) module name
    c) Error
    d) None
    View Answer

    Correct answer: A — __main__

  21. Which of the following is used to check module location?
    a) module.__file__
    b) module.path
    c) module.dir
    d) module.loc
    View Answer

    Correct answer: A — module.__file__

  22. What will be printed?
    1 import math as m
    2 print(m.factorial(5))
    a) 120
    b) 5
    c) Error
    d) None
    View Answer

    Correct answer: A — 120

  23. Which of the following is used to import specific attributes?
    a) from module import attr1, attr2
    b) import module.attr1, module.attr2
    c) using module.attr1, module.attr2
    d) require module.attr1, module.attr2
    View Answer

    Correct answer: A — from module import attr1, attr2

  24. What is the output of print(len(dir(os)))?
    a) Number of attributes in os module
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Number of attributes in os module

  25. Which of the following is used to import time module?
    a) import time
    b) import Time
    c) using time
    d) require time
    View Answer

    Correct answer: A — import time

  26. What will be printed?
    1 import time
    2 print(time.sleep(0))
    a) None
    b) 0
    c) Error
    d) sleep
    View Answer

    Correct answer: A — None

  27. Which of the following is used to import random module?
    a) import random
    b) import Random
    c) using random
    d) require random
    View Answer

    Correct answer: A — import random

  28. What is the output of print(type(random))?
    a) <class 'module'>
    b) <class 'dict'>
    c) <class 'list'>
    d) Error
    View Answer

    Correct answer: A — <class 'module'>

  29. Which of the following is used to import math module?
    a) import math
    b) import Math
    c) using math
    d) require math
    View Answer

    Correct answer: A — import math

  30. What will be printed?
    1 import math
    2 print(math.pow(2,3))
    a) 8.0
    b) 8
    c) Error
    d) None
    View Answer

    Correct answer: A — 8.0

  31. Which of the following is used to import os module?
    a) import os
    b) import OS
    c) using os
    d) require os
    View Answer

    Correct answer: A — import os

  32. What is the output of print(os.getcwd())?
    a) Current working directory
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Current working directory

  33. Which of the following is used to import sys module?
    a) import sys
    b) import Sys
    c) using sys
    d) require sys
    View Answer

    Correct answer: A — import sys

  34. What will be printed?
    1 import sys
    2 print(sys.platform)
    a) Platform name
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Platform name

  35. Which of the following is used to import datetime module?
    a) import datetime
    b) import DateTime
    c) using datetime
    d) require datetime
    View Answer

    Correct answer: A — import datetime

  36. What is the output of print(datetime.datetime.now().year)?
    a) Current year
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Current year

  37. Which of the following is used to import re module?
    a) import re
    b) import Re
    c) using re
    d) require re
    View Answer

    Correct answer: A — import re

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

    Correct answer: A — Edu

  39. Which of the following is used to import functools module?
    a) import functools
    b) import Functools
    c) using functools
    d) require functools
    View Answer

    Correct answer: A — import functools

  40. What is the output of print(functools.reduce(lambda x,y:x+y,[1,2,3]))?
    a) 6
    b) 5
    c) Error
    d) None
    View Answer

    Correct answer: A — 6

  41. Which of the following is used to import itertools module?
    a) import itertools
    b) import Itertools
    c) using itertools
    d) require itertools
    View Answer

    Correct answer: A — import itertools

  42. What will be printed?
    1 import itertools
    2 print(list(itertools.permutations([1,2],2)))
    a) [(1,2),(2,1)]
    b) [(1,2)]
    c) [1,2]
    d) Error
    View Answer

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

  43. Which of the following is used to import collections module?
    a) import collections
    b) import Collections
    c) using collections
    d) require collections
    View Answer

    Correct answer: A — import collections

  44. What is the output of print(collections.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})

  45. Which of the following is used to import statistics module?
    a) import statistics
    b) import Statistics
    c) using statistics
    d) require statistics
    View Answer

    Correct answer: A — import statistics

  46. What will be printed?
    1 import statistics
    2 print(statistics.mean([1,2,3]))
    a) 2
    b) 3
    c) Error
    d) None
    View Answer

    Correct answer: A — 2

  47. Which of the following is used to import decimal module?
    a) import decimal
    b) import Decimal
    c) using decimal
    d) require decimal
    View Answer

    Correct answer: A — import decimal

  48. What is the output of print(decimal.Decimal('0.1')+decimal.Decimal('0.2'))?
    a) 0.3
    b) 0.30000000000000004
    c) Error
    d) None
    View Answer

    Correct answer: A — 0.3

  49. Which of the following is used to import fractions module?
    a) import fractions
    b) import Fractions
    c) using fractions
    d) require fractions
    View Answer

    Correct answer: A — import fractions

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

    Correct answer: A — 1/2

Quick Links to Explore