Python Programming MCQs OLC
Python Programming MCQs OLC
21. Which rounding strategy does Python’s built-in 32. PEP stands for?
round() function use? (a) Python Enhancement Proposal
(a) Round down (b) Python Exposure Proposal
(b) Round half to even (c) Python Exposed Proposal
(c) trauncate (d) Round half up (d) None
22. When a value is truncated to 3 decimal places, which 33. a = [1, 8] _____________ print(a * 3)?
of the following is true? (a) Error
(a) Positive numbers are rounded up and negative (b) [1,8]
numbers are rounded down. (c) [1,8,1,8,1,8,1,8,1,8,1,8,1,8]
(b) Positive numbers are rounded down and nega- (d) [1,8,1,8,1,8]
tive numbers are rounded up. 34. Can python support parameter-passing mechanism?
23. The minsplit parameter to split() specifies the (a) Yes (b) No
minimum number of splits to make to the input 35. The _____________ is a way to declare a list in one
string. line of code.
(a) TRUE (b) FALSE (a) lambda (b) list manipulation
24. In Python which built-in function returns the unique (c) list comprehension (d) zip
number assigned to an object? 36. When a function makes a call to itself, it is termed as
(a) refnum() (b) ref() _____________.
(c) id() (d) none of these (a) anonymous (b) recursion
25. In Python, a variable must be declared before it is (c) repetition (d) none
assigned a value. 37. _____________ is a technique that allows us to
(a) TRUE (b) FALSE retrieve only a part of a list, tuple, or string.
26. You are a Python developer at Turing. You want to (a) Slicing (b) Operator
get the current position of the file. How can you do (c) Indexing (d) Decorator
it? 38. The function pow(x,y,z) is evaluated as:
(a) fp.seek() (b) fp.loc() (a) (x**y)**z (b) (x**y)/z
(c) fp.tell() (d) fp.pos() (c) (x**y) % z (d) (x**y)*z
27. Which of the following statements about xrange in 39. a={4,5,6} , b={2,8,6} _____________ a–b?
python are FALSE? (a) {4,5} (b) {6}
(a) xange provides a way to generate a list of (c) Both a and b (d) None
integers 40. Which of the following Bitwise operators sets each
(b) The xrange generates a static list at run-time bit to 1, if only one of them is 1, i.e. if only one of the
(c) xrange returns a Python list object two operands are 1.
(d) if you want to create a big list object, xrange is (a) OR (b) AND
the better choice to use (c) NOT (d) XOR
28. print(2**(3**2), (2**3)**2, (2**3)**3)? 41. How to compare two objects and check whether they
(a) 64, 512, 64 (b) 64, 64, 64 have the same memory locations?
(c) 512, 512, 512 (d) 512, 64, 512 (a) is operator (b) in operator
29. The {} side {1} {2}'.format('bright', 'of', 'life') (c) ** (d) <==>
(a) Error 42. How to display only the day number of year in
(b) The bright side of life Python?
(c) no output (a) date.strftime(“%p”)
(d) The {bright} side {of} {life}' (b) date.strftime(“%j”)
30. Which of the following is incorrect about mode to (c) date.strftime(“%H”)
open the file? (d) date.strftime(“%I”)
(a) a+ (b) r+ 43. How to swap cases in Python i.e. lowercase to
(c) rw (d) w+ uppercase and vice versa?
31. Which of the following statements is INCORRECT (a) casefold() method (b) title() method
about a valid attribute of a file object in Python? (c) swapcase() method (d) case() method
(a) file.size (b) file.mode 44. Which of the following is the correct way to indicate
(c) file.name (d) file.closed Hexadecimal Notation in Python?
Multiple Choice Questions 3
Answers
1. (b) 2. (c) 3. (a) 4. (d) 5. (b) 6. (b) 7. (d) 8. (c) 9. (b) 10. (a) 11. (b) 12. (c)
13. (d) 14. (b) 15. (c) 16. (b) 17. (a) 18. (a) 19. (d) 20. (a) 21. (b) 22. (b) 23. (b) 24. (c)
25. (b) 26. (b) 27. (d) 28. (d) 29. (c) 30. (a) 31. (d) 32. (a) 33. (d) 34. (a) 35. (c) 36. (b)
37. (a) 38. (c) 39. (a) 40. (d) 41. (a) 42. (b) 43. (c) 44. (d) 45. (b) 46. (c) 47. (a) 48. (a)
49. (b) 50. (b) 51. (c) 52. (a) 53. (b) 54. (d)