Learn Mode

Python — Python Mcq Set 14

Review questions, analyze choices, and reveal correct answers at your own pace.

1. What will be the output of the following Python code? elements = [0, 1, 2] def incr(x): return x+1 print(list(map(elements, incr)))

A. [1, 2, 3]
B. [0, 1, 2]
C. error
D. none of the mentioned
Correct Option: error

2. What will be the output of the following Python code? elements = [0, 1, 2] def incr(x): return x+1 print(list(map(incr, elements)))

A. [1, 2, 3]
B. [0, 1, 2]
C. error
D. none of the mentioned
Correct Option: [1, 2, 3]

3. What will be the output of the following Python code? x = ['ab', 'cd'] print(list(map(upper, x)))

A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’]
C. error
D. none of the mentioned
Correct Option: error

4. What will be the output of the following Python code? def to_upper(k): return k.upper() x = ['ab', 'cd'] print(list(map(upper, x)))

A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’]
C. none of the mentioned
D. error
Correct Option: error

5. What will be the output of the following Python code? def to_upper(k): return k.upper() x = ['ab', 'cd'] print(list(map(to_upper, x)))

A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’]
C. none of the mentioned
D. error
Correct Option: [‘AB’, ‘CD’]

6. What will be the output of the following Python code? def to_upper(k): k.upper() x = ['ab', 'cd'] print(list(map(to_upper, x)))

A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’]
C. none of the mentioned
D. error
Correct Option: none of the mentioned

7. What will be the output of the following Python code? x = ['ab', 'cd'] print(map(len, x))

A. [‘ab’, ‘cd’]
B. [2, 2]
C. [‘2’, ‘2’]
D. None of the mentioned
Correct Option: None of the mentioned

8. What will be the output of the following Python code? x = ['ab', 'cd'] print(list(map(len, x)))

A. [‘ab’, ‘cd’]
B. [2, 2]
C. [‘2’, ‘2’]
D. None of the mentioned
Correct Option: [2, 2]

9. What will be the output of the following Python code? x = ['ab', 'cd'] print(len(map(list, x)))

A. [2, 2]
B. 2
C. 4
D. none of the mentioned
Correct Option: none of the mentioned

10. What will be the output of the following Python code? x = ['ab', 'cd'] print(len(list(map(list, x))))

A. 2
B. 4
C. error
D. none of the mentioned
Correct Option: 2

11. What will be the output of the following Python code? x = ['ab', 'cd'] print(len(list(map(list, x))))))

A. 2
B. 4
C. error
D. none of the mentioned
Correct Option: error

12. What will be the output of the following Python code? x = ['ab', 'cd'] print(list(map(list, x)))

A. [‘a’, ‘b’, ‘c’, ‘d’]
B. [[‘ab’], [‘cd’]]
C. [[‘a’, ‘b’], [‘c’, ‘d’]]
D. none of the mentioned
Correct Option: [[‘a’, ‘b’], [‘c’, ‘d’]]

13. What will be the output of the following Python code? x = [12, 34] print(len(list(map(len, x))))

A. 2
B. 1
C. error
D. none of the mentioned
Correct Option: error

14. What will be the output of the following Python code? x = [12, 34] print(len(list(map(int, x))))

A. 2
B. 1
C. error
D. none of the mentioned
Correct Option: 2

15. What will be the output of the following Python code? x = [12, 34] print(len(''.join(list(map(int, x)))))

A. 4
B. 2
C. error
D. none of the mentioned
Correct Option: error

16. What will be the output of the following Python code? x = [12, 34] print(len(''.join(list(map(str, x)))))

A. 4
B. 5
C. 6
D. error
Correct Option: 4

17. What will be the output of the following Python code? x = [12, 34] print(len(' '.join(list(map(int, x)))))

A. 4
B. 5
C. 6
D. error
Correct Option: error

18. What will be the output of the following Python code? x = [12.1, 34.0] print(len(' '.join(list(map(str, x)))))

A. 6
B. 8
C. 9
D. error
Correct Option: 9

19. What will be the output of the following Python code? x = [12.1, 34.0] print(' '.join(list(map(str, x))))

A. 12 1 34 0
B. 12.1 34
C. 121 340
D. 12.1 34.0
Correct Option: 12.1 34.0

20. What will be the output of the following Python code? x = [[0], [1]] print(len(' '.join(list(map(str, x)))))

A. 2
B. 3
C. 7
D. 8
Correct Option: 7

21. What will be the output of the following Python code? x = [[0], [1]] print((' '.join(list(map(str, x)))))

A. (‘[0] [1]’,)
B. (’01’,)
C. [0] [1]
D. 01
Correct Option: [0] [1]

22. What will be the output of the following Python code? x = [34, 56] print((''.join(list(map(str, x))),))

A. 3456
B. (3456)
C. (‘3456’)
D. (‘3456’,)
Correct Option: (‘3456’,)

23. What will be the output of the following Python code? x = [34, 56] print((''.join(list(map(str, x)))),)

A. 3456
B. (3456)
C. (‘3456’)
D. (‘3456’,)
Correct Option: 3456

24. What will be the output of the following Python code? x = [34, 56] print(len(map(str, x)))

A. [34, 56]
B. [’34’, ’56’]
C. 34 56
D. error
Correct Option: error

25. What will be the output of the following Python code? x = 'abcd' print(list(map(list, x)))

A. [‘a’, ‘b’, ‘c’, ‘d’]
B. [‘abcd’]
C. [[‘a’], [‘b’], [‘c’], [‘d’]]
D. none of the mentioned
Correct Option: [[‘a’], [‘b’], [‘c’], [‘d’]]

26. What will be the output of the following Python code? x = abcd print(list(map(list, x)))

A. [‘a’, ‘b’, ‘c’, ‘d’]
B. [‘abcd’]
C. [[‘a’], [‘b’], [‘c’], [‘d’]]
D. none of the mentioned
Correct Option: none of the mentioned

27. What will be the output of the following Python code? x = 1234 print(list(map(list, x)))

A. [1, 2, 3, 4]
B. [1234]
C. [[1], [2], [3], [4]]
D. none of the mentioned
Correct Option: none of the mentioned

28. What will be the output of the following Python code? x = 1234 print(list(map(list, [x])))

A. [1, 2, 3, 4]
B. [1234]
C. [[1], [2], [3], [4]]
D. none of the mentioned
Correct Option: none of the mentioned

29. What will be the output of the following Python code? x = 'abcd' print(list(map([], x)))

A. [‘a’, ‘b’, ‘c’, ‘d’]
B. [‘abcd’]
C. [[‘a’], [‘b’], [‘c’], [‘d’]]
D. none of the mentioned
Correct Option: none of the mentioned

30. which of these is false about a package?

A. A package can have subfolders and modules
B. Each import package need not introduce a namespace
C. import folder.subfolder.mod1 imports packages
D. from folder.subfolder.mod1 import objects imports packages
Correct Option: Each import package need not introduce a namespace

31. Which of these definitions correctly describes a module?

A. Denoted by triple quotes for providing the specification of certain program elements
B. Design and implementation of specific functionality to be incorporated into a program
C. Defines the specification of how it is to be used
D. Any program that reuses code
Correct Option: Design and implementation of specific functionality to be incorporated into a program

32. Which of the following is not an advantage of using modules?

A. Provides a means of reuse of program code
B. Provides a means of dividing up tasks
C. Provides a means of reducing the size of the program
D. Provides a means of testing individual parts of the program
Correct Option: Provides a means of reducing the size of the program

33. Program code making use of a given module is called a ______ of the module.

A. Client
B. Docstring
C. Interface
D. Modularity
Correct Option: Client

34. ______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.

A. Interface
B. Modularity
C. Client
D. Docstring
Correct Option: Docstring

35. Which of the following is true about top-down design process?

A. The details of a program design are addressed before the overall design
B. Only the details of the program are addressed
C. The overall design of the program is addressed before the details
D. Only the design of the program is addressed
Correct Option: The overall design of the program is addressed before the details

36. What will be the output of the following Python code? #mod1 def change(a): b=[x*2 for x in a] print(b) #mod2 def change(a): b=[x*x for x in a] print(b) from mod1 import change from mod2 import change #main s=[1,2,3] change(s)

A. [2,4,6]
B. [1,4,9]
C. [2,4,6] [1,4,9]
D. There is a name clash
Correct Option: There is a name clash

37. Which of the following isn’t true about main modules?

A. When a python file is directly executed, it is considered main module of a program
B. Main modules may import any number of modules
C. Special name given to main modules is: __main__
D. Other main modules can import main modules
Correct Option: Other main modules can import main modules

38. Which of the following is not a valid namespace?

A. Global namespace
B. Public namespace
C. Built-in namespace
D. Local namespace
Correct Option: Public namespace

39. Which of the following is false about “import modulename” form of import?

A. The namespace of imported module becomes part of importing module
B. This form of import prevents name clash
C. The namespace of imported module becomes available to importing module
D. The identifiers in module are accessed as: modulename.identifier
Correct Option: The namespace of imported module becomes part of importing module

40. Which of the following is false about “from-import” form of import?

A. The syntax is: from modulename import identifier
B. This form of import prevents name clash
C. The namespace of imported module becomes part of importing module
D. The identifiers in module are accessed directly as: identifier
Correct Option: This form of import prevents name clash

41. Which of the statements about modules is false?

A. In the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported
B. dir() built-in function monitors the items in the namespace of the main module
C. In the “from-import” form of import, all identifiers regardless of whether they are private or public are imported
D. When a module is loaded, a compiled version of the module with file extension .pyc is automatically produced
Correct Option: In the “from-import” form of import, all identifiers regardless of whether they are private or public are imported

42. What will be the output of the following Python code? from math import factorial print(math.factorial(5))

A. 120
B. Nothing is printed
C. Error, method factorial doesn’t exist in math module
D. Error, the statement should be: print(factorial(5))
Correct Option: Error, the statement should be: print(factorial(5))

43. What is returned by math.ceil(3.4)?

A. 3
B. 4
C. 4.0
D. 3.0
Correct Option: 4

44. What is the value returned by math.floor(3.4)?

A. 3
B. 4
C. 4.0
D. 3.0
Correct Option: 3

45. What will be the output of print(math.copysign(3, -1))?

A. 1
B. 1.0
C. -3
D. -3.0
Correct Option: -3.0

46. What is displayed on executing print(math.fabs(-3.4))?

A. -3.4
B. 3.4
C. 3
D. -3
Correct Option: 3.4

47. Is the output of the function abs() the same as that of the function math.fabs()?

A. sometimes
B. always
C. never
D. none of the mentioned
Correct Option: sometimes

48. What is the value returned by math.fact(6)?

A. 720
B. 6
C. [1, 2, 3, 6]
D. error
Correct Option: error

49. What is the value of x if x = math.factorial(0)?

A. 0
B. 1
C. error
D. none of the mentioned
Correct Option: 1

50. What is math.factorial(4.0)?

A. 24
B. 1
C. error
D. none of the mentioned
Correct Option: 24

51. What will be the output of print(math.factorial(4.5))?

A. 24
B. 120
C. error
D. 24.0
Correct Option: error

52. What is math.floor(0o10)?

A. 8
B. 10
C. 0
D. 9
Correct Option: 8