0% found this document useful (0 votes)
65 views15 pages

Python MCQ 100

The document contains 100 multiple choice questions (MCQs) focused on Python technical knowledge, aimed at placement preparation. Each question includes four options (A-D) with an answer key provided at the end. Topics cover various aspects of Python programming, including data types, functions, error handling, and more.

Uploaded by

rrathisha44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views15 pages

Python MCQ 100

The document contains 100 multiple choice questions (MCQs) focused on Python technical knowledge, aimed at placement preparation. Each question includes four options (A-D) with an answer key provided at the end. Topics cover various aspects of Python programming, including data types, functions, error handling, and more.

Uploaded by

rrathisha44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Python Technical MCQs for Placement Preparation

Python Technical MCQs for Placement Preparation


100 Multiple Choice Questions (MCQs) — Questions followed by options (A-D). Answer key
provided at the end.
1. What is the output of: print(type(lambda x: x))
A. <class 'function'>
B. <class 'lambda'>
C. <class 'generator'>
D. <class 'object'>
2. Which of the following is immutable?
A. list
B. dict
C. tuple
D. set
3. What does 'PEP' stand for in Python community?
A. Python Enhancement Proposal
B. Programming Enhancement Proposal
C. Python Execution Plan
D. Performance Enhancement Plan
4. What is the result of '5' + 3 in Python 3?
A. 8
B. '53'
C. TypeError
D. '8'
5. Which keyword is used to create a generator?
A. gen
B. yield
C. return
D. lambda
6. Which built-in function returns an iterator of tuples, combining index and values?
A. zip()
B. enumerate()
C. iter()
D. map()
7. What is the output of: list(range(2,10,3))
A. [2,3,4,5,6,7,8,9]
B. [2,5,8]
C. [2,10]
D. [2,3,6,9]
8. Which method adds an element to the end of a list?
A. add()
B. append()
C. push()
D. insert_end()
9. Which statement is used to handle exceptions?
A. try/except
B. catch/except
C. try/catch
D. handle/except
10. What is the difference between '==' and 'is'?
A. '==' checks identity, 'is' checks equality
B. '==' checks equality of values, 'is' checks identity
C. Both are same
D. 'is' is for strings only
11. Which of these will create a set?
A. {}
B. set()
C. []
D. ()
12. How do you comment multiple lines in Python?
A. /* ... */
B. //
C. Using triple quotes '''...''' or """..."""
D. <!-- -->
13. What is a correct way to open a file for reading in binary?
A. open('file','r')
B. open('file','rb')
C. open('file','wb')
D. open('file','br')
14. Which of the following sorts a list in-place?
A. sorted(list)
B. list.sort()
C. list.sorted()
D. sort(list)
15. What does dict.get(key, default) return if key is missing?
A. Raises KeyError
B. None or default if provided
C. 0
D. '' (empty string)
16. Which is the correct way to define a class in Python?
A. class MyClass: pass
B. def MyClass: pass
C. class MyClass() {}
D. function MyClass()
17. What will len({'a':1,'b':2}) return?
A. 0
B. 1
C. 2
D. Error
18. Which module is used for regular expressions in Python?
A. re
B. regex
C. regexp
D. re2
19. Which of the following creates a shallow copy of a list?
A. list.copy()
B. list[:]
C. list(list)
D. All of the above
20. What is the output of: bool('False')
A. False
B. True
C. 0
D. TypeError
21. Which of these is NOT a valid Python data model method?
A. __init__
B. __str__
C. __repr__
D. __compare__
22. What does the 'with' statement provide?
A. Looping capability
B. Exception raising
C. Context manager for resource handling
D. Multithreading
23. How to create an empty dictionary?
A. {}
B. dict()
C. Both A and B
D. []
24. Which of the following removes and returns last element of a list?
A. remove()
B. pop()
C. delete()
D. discard()
25. What is list comprehension result of [x*x for x in range(3)]?
A. [0,1,4]
B. [1,4,9]
C. [0,1,2]
D. [1,2,3]
26. How do you create an anonymous function in Python?
A. def
B. lambda
C. anon
D. func
27. Which statement is true about Python's integers?
A. Fixed 32-bit
B. Fixed 64-bit
C. Arbitrary precision
D. Only positive
28. What will be the result of: 'abc'.upper()?
A. 'abc'
B. 'Abc'
C. 'ABC'
D. Error
29. Which method of a string returns substring count?
A. find()
B. count()
C. index()
D. slice()
30. How to check if an object is instance of a class?
A. type(obj) == Class
B. isinstance(obj, Class)
C. obj.is(Class)
D. instance(obj,Class)
31. Which of the following is true for Python's GIL?
A. Allows true parallel CPU bound multi-threading
B. Prevents multiple native threads from executing Python bytecodes at once
C. Only applies to Python 3.11+
D. Is a garbage collector
32. What does 'assert' do?
A. Raises AssertionError if condition false
B. Prints condition
C. Creates a variable
D. Skips condition
33. Which keyword makes a function return a generator?
A. return
B. yield
C. async
D. await
34. How to merge two dictionaries in Python 3.9+?
A. d1 + d2
B. d1 | d2
C. merge(d1,d2)
D. d1.update(d2)
35. What is the output of: isinstance(True, int)
A. True
B. False
C. TypeError
D. 0
36. Which function converts a string to a float?
A. int()
B. float()
C. str()
D. cast()
37. What is pickling in Python?
A. Encrypting data
B. Serializing objects to byte stream
C. Compressing files
D. Parsing CSV
38. Which operator is used for string formatting (old style)?
A. %
B. $
C. {}
D. &
39. Which of these iterates over keys and values of dict?
A. dict.items()
B. dict.values()
C. dict.keys()
D. dict.iter()
40. What's the output of: [i for i in range(5) if i%2]
A. [0,2,4]
B. [1,3]
C. [0,1,2,3,4]
D. []
41. Which of these is used to create virtual environments?
A. venv
B. virtualenv
C. conda
D. Any of the above
42. Which statement imports only sqrt from math module?
A. import math.sqrt
B. from math import sqrt
C. import sqrt from math
D. include math.sqrt
43. What is the use of __init__.py file?
A. Marks a directory as a package
B. Initializes variables only
C. Is required for modules
D. Is for tests only
44. Which of these raises StopIteration?
A. next() on exhausted iterator
B. len() on iterator
C. iter() on list
D. calling generator function
45. How to create a bytes literal?
A. b'hello'
B. 'hello'.bytes()
C. bytes('hello')
D. Both A and C
46. What will open('f','w') do if file exists?
A. Append to file
B. Truncate file and write
C. Raise Error
D. Read file
47. Which built-in creates an immutable sequence of unique elements?
A. tuple
B. set
C. frozenset
D. list
48. What does the 'pass' statement do?
A. Exits program
B. Placeholder that does nothing
C. Skips function
D. Raises exception
49. Which keyword is used to define asynchronous functions?
A. async
B. await
C. asyncdef
D. defer
50. What is the output of: sorted({3,1,2})
A. [1,2,3]
B. {1,2,3}
C. (1,2,3)
D. Error
51. Which method converts JSON string to Python object?
A. json.dumps
B. json.loads
C. json.load
D. json.parse
52. What's the result of: x = [1,2]; y = x; x.append(3); print(y)
A. [1,2]
B. [1,2,3]
C. Error
D. None
53. Which of these is true about list slicing a[1:5]?
A. Includes index 5
B. Excludes index 1
C. Excludes index 5
D. Is an in-place operation
54. Which function is used to get memory address?
A. id()
B. addr()
C. memory()
D. hex()
55. Which of these is NOT a Python keyword?
A. lambda
B. eval
C. yield
D. async
56. What is the correct way to declare type hints for a function returning int?
A. def f() -> int:
B. def f(): int
C. def f() : int
D. def f() => int
57. Which module helps with command line argument parsing?
A. sys
B. argparse
C. getopt
D. All of the above
58. What does enumerate(['a','b'])[1] return? (zero-based)
A. 'a'
B. (0,'a')
C. (1,'b')
D. Error
59. Which of these will create a dictionary comprehension?
A. {k:v for k,v in iterable}
B. [k:v for k,v in iterable]
C. dict{k:v}
D. {k:v; for k,v in iterable}
60. What will be printed by: print(0.1 + 0.2 == 0.3)
A. True
B. False
C. Error
D. 0.3
61. How to make a shallow copy of a dictionary?
A. dict.copy()
B. dict(dict)
C. {**dict}
D. All of the above
62. Which of these statements about Python strings is true?
A. Strings are mutable
B. Strings are immutable
C. Strings are lists
D. Strings are sets
63. What is the result of: tuple([1,2,3])
A. [1,2,3]
B. (1,2,3)
C. {1,2,3}
D. Error
64. Which built-in raises when indexing out of range for list?
A. IndexError
B. KeyError
C. ValueError
D. TypeError
65. Which method checks if object supports context manager protocol?
A. hasattr(obj,'__enter__') and hasattr(obj,'__exit__')
B. hasattr(obj,'__context__')
C. hasattr(obj,'with')
D. hasattr(obj,'__manage__')
66. Which of these creates a new generator?
A. (x for x in range(3))
B. [x for x in range(3)]
C. {x for x in range(3)}
D. list(range(3))
67. Which is used to run a module as script?
A. python -m module
B. python module.py
C. import module
D. exec(module)
68. What is the correct way to check for empty list?
A. if len(lst) == 0:
B. if not lst:
C. if lst == []:
D. Any of the above
69. Which statement is true about decorators?
A. They modify functions or classes
B. They are executed at function call time
C. They can only be applied to methods
D. They cannot accept arguments
70. What is the effect of 'from module import *'?
A. Imports only functions
B. Imports all public names into current namespace
C. Prevents import
D. Imports private names only
71. How to convert a list of strings to integers?
A. map(int, list)
B. [int(x) for x in list]
C. list(map(int,list))
D. All of the above
72. Which statement about multiprocessing vs threading is true?
A. threading bypasses GIL for CPU bound tasks
B. multiprocessing uses separate processes and can utilize multiple CPUs
C. multiprocessing shares memory automatically
D. threading is always faster
73. Which built-in returns an iterator that applies a function to all items?
A. filter()
B. map()
C. reduce()
D. apply()
74. Which of the following will NOT create a new reference to the same list?
A. b = a
B. b = a[:]
C. b = list(a)
D. b = copy.copy(a)
75. Which statement about __slots__ is true?
A. Allows dynamic attribute creation
B. Prevents creation of __dict__ per instance and can save memory
C. Is required for dataclasses
D. Enables multiple inheritance
76. How to read a file line by line efficiently?
A. file.read()
B. for line in file:
C. file.readlines()
D. file.readline() in loop without iterator
77. Which of these is true about lambda functions?
A. Can contain multiple statements
B. Are limited to single expression
C. Cannot be assigned to variables
D. Have name attribute set to function name
78. What does functools.lru_cache do?
A. Caches function calls to speed up repeated calls
B. Logs function usage
C. Runs function in separate thread
D. Encrypts result
79. Which of these methods serializes Python object to JSON string?
A. json.dumps
B. json.dump
C. pickle.dumps
D. pickle.dump
80. Which will correctly create a pandas DataFrame? (assume pandas imported)
A. pandas.DataFrame({'a':[1,2]})
B. pandas.df({'a':[1,2]})
C. DataFrame([1,2]) without import
D. None
81. Which built-in can be used to evaluate a string as Python expression?
A. exec
B. eval
C. interpret
D. run
82. What is the output of: list(map(lambda x: x*2, [1,2,3]))
A. [2,4,6]
B. (2,4,6)
C. map object
D. generator
83. Which function is used to get number of CPU cores?
A. os.cpu_count()
B. multiprocessing.count()
C. sys.cpu()
D. platform.cores()
84. Which method deletes a key from dict and returns its value?
A. del d[key]
B. d.pop(key)
C. d.remove(key)
D. d.delete(key)
85. What is the use of __name__ == '__main__'?
A. To check module name equals main and run code only when script executed directly
B. To import module
C. To declare main function
D. For package initialization
86. Which of these is correct about f-strings?
A. f"{var}" requires python 3.6+
B. f-strings are slower than % formatting
C. f-strings cannot include expressions
D. f-strings use format() under the hood
87. What does 'raise from' do?
A. Creates a new exception without context
B. Chains exceptions, preserving context
C. Suppresses exception
D. Retries operation
88. Which of these is NOT part of iterator protocol?
A. __iter__
B. __next__
C. __len__
D. next()
89. Which library is commonly used for HTTP requests?
A. urllib.request
B. requests
C. http.client
D. All of the above
90. What is the output of: {i:i*i for i in range(3)}
A. {0:0,1:1,2:4}
B. [(0,0),(1,1),(2,4)]
C. {0,1,4}
D. Error
91. Which of the following will create a coroutine?
A. def coro(): yield
B. async def coro(): await something
C. def coro(): return
D. lambda: None
92. Which of the following is used to measure execution time simply?
A. time.time()
B. time.perf_counter()
C. time.process_time()
D. Any of the above depending on requirement
93. How do you document a function so help() shows it?
A. Use comments above function
B. Assign to __doc__ or use a docstring triple quotes
C. Use annotation
D. Use logging
94. Which module provides abstract base classes for containers?
A. abc
B. collections.abc
C. typing
D. types
95. How to handle multiple exceptions in single except?
A. except (TypeError, ValueError):
B. except TypeError, ValueError:
C. except TypeError | ValueError:
D. except [TypeError,ValueError]:
96. Which of these makes a method a classmethod?
A. @staticmethod
B. @classmethod
C. def classmethod(self):
D. @method
97. Which of these sorts keys of dict while iterating in Python 3.7+?
A. dict preserves insertion order but not sorted
B. dict automatically sorts keys
C. dict is unordered
D. dict sorts keys by default
98. What will be the output: print('a','b',sep='-')
A. a b
B. a-b
C. 'a-b'
D. Error
99. Which of following is correct for type annotation of list of ints?
A. List[int] (from typing)
B. list<int>
C. (int)list
D. [int]
100. Which of the following statements about Python's garbage collector is true?
A. It only uses reference counting
B. It uses reference counting and generational GC to collect cycles
C. Python doesn't have GC
D. GC must be manually invoked always
Answer Key:
1. A
2. C
3. A
4. C
5. B
6. B
7. B
8. B
9. A
10. B
11. B
12. C
13. B
14. B
15. B
16. A
17. C
18. A
19. D
20. B
21. D
22. C
23. C
24. B
25. A
26. B
27. C
28. C
29. B
30. B
31. B
32. A
33. B
34. B
35. A
36. B
37. B
38. A
39. A
40. B
41. D
42. B
43. A
44. A
45. D
46. B
47. C
48. B
49. A
50. A
51. B
52. B
53. C
54. A
55. B
56. A
57. D
58. D
59. A
60. B
61. D
62. B
63. B
64. A
65. A
66. A
67. A
68. D
69. A
70. B
71. D
72. B
73. B
74. A
75. B
76. B
77. B
78. A
79. A
80. A
81. B
82. A
83. A
84. B
85. A
86. A
87. B
88. C
89. D
90. A
91. B
92. D
93. B
94. B
95. A
96. B
97. A
98. B
99. A
100. B

You might also like