Python is a popular programming language known for its simplicity and versatility. It is widely used in web development, data science, automation, and artificial intelligence. Practicing Python MCQs (multiple-choice questions)helps test your understanding of key topics like variables, loops, functions, and object-oriented programming in an easy and interactive way.
In this Python tutorial, let's learn the most commonly asked Python MCQs. Python MCQs with answers improve problem-solving skills and prepare you for exams and interviews. Regular practice with Python objective questions and online tests boosts confidence and understanding.
Top 100 Python MCQ Questions and Answers
Explore the top Python MCQ questions and answers to test your knowledge of key concepts like loops, functions, and object-oriented programming. These Python quiz questions help in exam preparation and improve problem-solving skills.
Q 1. Who developed Python, and when was it first released?
(a) Guido van Rossum, 1991
(b) Dennis Ritchie, 1985
(c) James Gosling, 1995
(d) Bjarne Stroustrup, 1979
The correct answer is (a) Guido van Rossum, 1991.
Explanation: Python was developed by Guido van Rossum and released as Python 0.9.0 in February 1991.
Q 2. When did Python 3.0 release, and what was its major focus?
(a) 2008, backward compatibility
(b) 2000, performance improvements
(c) 2008, breaking backward compatibility
(d) 2005, multi-threading
The correct answer is (c) 2008, breaking backward compatibility.
Explanation: Python 3.0 was released in December 2008 and focused on fixing design flaws in the language, even at the cost of breaking backward compatibility.
Q 3. Who maintains Python today?
(a) Microsoft
(b) Python Software Foundation
(c) Oracle
(d) Google
The correct answer is (b) Python Software Foundation.
Explanation:Python is maintained by the Python Software Foundation (PSF), a non-profit organization.
Q 4. What is Python primarily known for?
(a) Low-level programming
(b) Ease of readability and simplicity
(c) Hardware programming
(d) Data compression
The correct answer is (b) Ease of readability and simplicity.
Explanation: Python is widely regarded for its easy-to-read syntax and emphasis on developer productivity.
Q 5. What type of programming language is Python?
(a) Compiled language
(b) Interpreted language
(c) Machine language
(d) Assembly language
The correct answer is (b) Interpreted language.
Explanation: Python is an interpreted language, meaning its code is executed line by line by the interpreter.
Q 6. What is the correct file extension for Python files?
(a) .pt
(b) .py
(c) .pyt
(d) .python
The correct answer is (b) .py.
Explanation: Python files use the `.py` extension to save Python source code.
Q 7. Which of the following is a mutable data type in Python?
(a) Tuple
(b) String
(c) List
(d) Integer
The correct answer is (c) List.
Explanation:Lists in Python are mutable, meaning their content can be changed after creation.
Q 8. Who is responsible for Python's open-source development and maintenance?
(a) The Python Community
(b) Python Software Foundation (PSF)
(c) Guido van Rossum
(d) Open Source Initiative
The correct answer is (b) Python Software Foundation (PSF).
Explanation: The Python Software Foundation (PSF) is a non-profit organization that manages Python's development and promotes its use worldwide.
Q 9. What does the term "PEP" stand for in Python development?
(a) Python Execution Protocol
(b) Python Enhancement Proposal
(c) Python Exception Processing
(d) Python Error Policy
The correct answer is (b) Python Enhancement Proposal.
Explanation: A PEP, or Python Enhancement Proposal, is a document that proposes changes or improvements to the Python language.
Q 10. Which keyword is used to define a function in Python?
(a) function
(b) define
(c) def
(d) func
The correct answer is (c) def.
Explanation: The `def` keyword is used to define a function in Python. For example: def my_function():.
Q 11. What is the output of print(type(5)) in Python?
(a) <class 'integer'>
(b) <class 'int'>
(c) int
(d) Error
The correct answer is (b) <class 'int'>.
Explanation: In Python, the `type()` function is used to check the type of an object. For integers, the type is <class 'int'>.
Q 12. What is the correct syntax to import a module in Python?
(a) import module_name
(b) include module_name
(c) from module_name import
(d) import module_name as alias
The correct answer is (a) import module_name.
Explanation: In Python, the correct syntax to import a module is import module_name.
Q 13. What will be the output of the following Python code?
x = [1, 2, 3]
y = x
y[0] = 100
print(x)
(a) [100, 2, 3]
(b) [1, 2, 3]
(c) [1, 100, 3]
(d) [100, 100, 3]
The correct answer is (a) [100, 2, 3].
Explanation: The list y is a reference to the list x. Therefore, modifying y[0] will also modify x.
Q 14. What does the 'break' statement do in a loop in Python?
(a) Exits the loop immediately
(b) Pauses the loop
(c) Continues the loop
(d) Restarts the loop
The correct answer is (a) Exits the loop immediately.
Explanation: The break statement is used to exit from the current loop and transfer control to the next statement after the loop.
Q 15. Which of the following is an immutable data type in Python?
(a) List
(b) Set
(c) String
(d) Dictionary
The correct answer is (c) String.
Explanation:Strings in Python are immutable, meaning their content cannot be modified after they are created.
Q 18. What is the output of the following Python code?
deffoo(a, b=10):
return a + b
print(foo(5))
(a) 5
(b) 10
(c) 15
(d) Error
The correct answer is (c) 15.
Explanation: The function foo uses a default value for b which is 10. So, the result of foo(5) is 5 + 10 = 15.
Q 19. What is the purpose of the 'pass' statement in Python?
(a) To terminate the program
(b) To skip the current iteration of a loop
(c) To define an empty function or class
(d) To raise an exception
The correct answer is (c) To define an empty function or class.
Explanation: The pass statement is used as a placeholder to define empty functions, classes, or control structures that are syntactically required but not yet implemented.
Q 20. What does the following Python code output?
x = [1, 2, 3, 4]
x = x[::-1]
print(x)
(a) [1, 2, 3, 4]
(b) [4, 3, 2, 1]
(c) [1, 4, 3, 2]
(d) Error
The correct answer is (b) [4, 3, 2, 1].
Explanation: The slicing operation [::-1] reverses the list.
Q 21. Which of the following is the correct way to define a class in Python?
(a) class MyClass {}
(b) def MyClass(): pass
(c) class MyClass: pass
(d) create class MyClass:
The correct answer is (c) class MyClass: pass.
Explanation: The class keyword is used to define a class in Python. The correct syntax is class MyClass: pass.
Q 22. Which of the following statements is used to create a set in Python?
(a) set = {1, 2, 3}
(b) set = [1, 2, 3]
(c) set = (1, 2, 3)
(d) set = set(1, 2, 3)
The correct answer is (a) set = {1, 2, 3}.
Explanation: Sets in Python are created using curly braces {}.
Q 23. What is the result of the following Python code?
x = [1, 2, 3, 4]
x.append([5, 6])
print(len(x))
(a) 5
(b) 6
(c) 7
(d) 8
The correct answer is (b) 6.
Explanation: The append() method adds an entire list as a single element, so the length of the list becomes 6.
Q 24. What does the following code print?
x = {'a': 1, 'b': 2}
x['c'] = 3
print(x)
(a) {'a': 1, 'b': 2, 'c': 3}
(b) {'a': 1, 'b': 2}
(c) {'c': 3, 'a': 1, 'b': 2}
(d) Error
The correct answer is (a) {'a': 1, 'b': 2, 'c': 3}.
Explanation: In Python, you can add new key-value pairs to a dictionary in Python using the dictionary[key] = value syntax.
Q 25. What is the output of the following Python code?
for i inrange(3):
if i == 1:
continueprint(i)
(a) 0 1 2
(b) 0 2
(c) 1 2
(d) Error
The correct answer is (b) 0 2.
Explanation: The continue statement causes the loop to skip the current iteration, so the number 1 is not printed.
Q 26. What is the correct syntax to define a function in Python?
(a) def function_name[]:
(b) function function_name():
(c) def function_name():
(d) function_name(): def
The correct answer is (c) def function_name():.
Explanation: The def keyword is used to define a function in Python, followed by the function name and parentheses.
Q 27. Which of the following data types is immutable in Python?
(a) List
(b) Set
(c) Dictionary
(d) Tuple
The correct answer is (d) Tuple.
Explanation: Tuples are immutable, meaning their values cannot be changed after creation, unlike lists, sets, and dictionaries which are mutable data types in Python.
Q 28. What will be the output of the following Python code?
def func(x, y=[]):
y.append(x)
return y
print(func(10))
print(func(20, []))
print(func(30))
(a) [10] [20] [30]
(b) [10] [30] [30]
(c) [10] [20] [30, 10]
(d) [10, 30] [20] [30]
The correct answer is (c) [10] [20] [30, 10].
Explanation: Default arguments in Python are evaluated only once when the function is defined. In the first and third calls, the same list is used for the y argument, so the values are added to the same list.
Q 29. What is the correct way to open a file in Python for reading?
(a) open("file.txt", "r")
(b) open("file.txt")
(c) open("file.txt", "read")
(d) open("file.txt", "w")
The correct answer is (a) open("file.txt", "r").
Explanation: To open a file in Python for reading, you use the open() function with the mode "r", which stands for "read".
Q 30. How would you access the second element of the following Python list?
my_list = [10, 20, 30, 40]
(a) my_list[2]
(b) my_list[1]
(c) my_list[0]
(d) my_list[3]
The correct answer is (b) my_list[1].
Explanation: In Python, list indices start at 0, so the second element is accessed using index 1.
Q 31. Which of the following statements is true about Python lists?
(a) Lists are immutable
(b) Lists are ordered and mutable
(c) Lists are unordered and immutable
(d) Lists are ordered but immutable
The correct answer is (b) Lists are ordered and mutable.
Explanation: Lists in Python are ordered collections of elements and can be modified after creation, making them mutable.
Q 32. Which of the following is used to handle exceptions in Python?
(a) try...except
(b) catch...finally
(c) exception...handle
(d) catch...except
The correct answer is (a) try...except.
Explanation:Exception handling in Python is done using the try...except block. The try block contains the code that might throw an exception, and the except block handles the exception.
Q 33. What is the output of the following Python code?
def func(a, b=10):
return a + b
print(func(5))
print(func(5, 15))
(a) 15 20
(b) 15 15
(c) 5 15
(d) 10 15
The correct answer is (a) 15 20.
Explanation: In the first call, b takes the default value of 10, so the result is 5 + 10 = 15. In the second call, b is explicitly set to 15, so the result is 5 + 15 = 20.
Q 34. What is the correct syntax for a lambda function in Python?
(a) lambda x: x + 2
(b) lambda x, y: return x + y
(c) lambda: x + y
(d) lambda x: return x + 2
The correct answer is (a) lambda x: x + 2.
Explanation:Lambda functions in Python are anonymous functions defined using the lambda keyword, followed by the arguments and the expression. The return keyword is not used in lambda functions.
Q 35. Which of the following is used to create a generator in Python?
(a) def function_name(): yield
(b) def function_name(): return
(c) generator function()
(d) function_name() generator
The correct answer is (a) def function_name(): yield.
Explanation: Generators in Python are created using the yield keyword inside a function. When the function is called, it returns a generator object.
Q 36. What will be the result of the following code?
x = 10defchange(x):
x = 20return x
change(x)
print(x)
(a) 10
(b) 20
(c) Error
(d) None
The correct answer is (a) 10.
Explanation: In Python, integers are immutable. The variable x inside the function is a local variable and does not affect the global variable x.
Q 37. Which of the following statements about Python's dictionary is false?
(a) Keys must be unique
(b) Values can be duplicate
(c) Dictionaries are ordered in Python 3.7 and above
(d) Keys can be mutable
The correct answer is (d) Keys can be mutable.
Explanation: Dictionary keys must be immutable (e.g., strings, numbers, tuples). Lists and other mutable types cannot be used as dictionary keys.
Q 38. Which of the following statements is true about Python sets?
(a) Sets allow duplicate elements
(b) Sets are ordered collections
(c) Sets are unordered collections
(d) Sets can store only integers
The correct answer is (c) Sets are unordered collections.
Explanation: Sets in Python are unordered collections of unique elements. They do not allow duplicate elements and are not indexed like lists or tuples.
Q 39. What will be the output of the following Python code?
def func(a=5, b=10):
return a * b
print(func())
print(func(2, 3))
(a) 50 6
(b) 15 15
(c) 5 30
(d) 50 30
The correct answer is (a) 50 6.
Explanation: In the first call, the default values for a and b are used, so the result is 5 * 10 = 50. In the second call, the values 2 and 3 are passed, so the result is 2 * 3 = 6.
Q 40. What does the following Python code do?
x = [1, 2, 3]
y = [4, 5, 6]
z = x + y
print(z)
(a) Merges the two lists into a single list
(b) Prints an error
(c) Creates a tuple with the two lists
(d) Concatenates the two lists into a tuple
The correct answer is (a) Merges the two lists into a single list.
Explanation: The + operator in Python, when applied to lists, concatenates them, resulting in a new list containing all elements from both lists.
Q 41. Which of the following is used to handle multiple exceptions in Python?
(a) except(Exception1, Exception2)
(b) except (Exception1 or Exception2)
(c) except (Exception1, Exception2) as e
(d) except (Exception1 or Exception2) as e
The correct answer is (a) except(Exception1, Exception2).
Explanation: In Python, you can handle multiple exceptions by specifying them as a tuple in the except clause.
Q 42. What is the output of the following Python code?
a = [1, 2, 3]
b = a
b[0] = 10
print(a)
(a) [10, 2, 3]
(b) [1, 2, 3]
(c) [10, 2]
(d) [10, 2, 3, 10]
The correct answer is (a) [10, 2, 3].
Explanation: In Python, lists are mutable, and when you assign a list to another variable (like b = a), they both point to the same object. Modifying b also modifies a.
Q 43. What is the output of the following Python code?
x = {1, 2, 3, 4}
y = {3, 4, 5, 6}
z = x & y
print(z)
(a) {1, 2, 3, 4, 5, 6}
(b) {3, 4}
(c) {5, 6}
(d) {1, 2}
The correct answer is (b) {3, 4}.
Explanation: The & operator is used to find the intersection of two sets. It returns only the elements that are present in both sets.
Q 44. What is the output of the following code?
x = "Python"
y = "Programming"
z = x + " " + y
print(z)
(a) Python Programming
(b) PythonProgramming
(c) Python + Programming
(d) Error
The correct answer is (a) Python Programming.
Explanation: In Python, the + operator is used for string concatenation. The result of x + " " + y is the two strings combined with a space in between.
Q 45. What is the difference between "is" and "==" in Python?
(a)is checks for object identity, == checks for equality of values
(b)is checks for equality of values, == checks for object identity
(c)is is used for strings only
(d)== is used to compare objects, is is used for arithmetic operations
The correct answer is (a) is checks for object identity, == checks for equality of values.
Explanation: The is operator checks if two objects reference the same memory location, while == checks if the values of the objects are equal.
Q 46. Which method is used to add an element to a list in Python?
(a) append()
(b) insert()
(c) add()
(d) push()
The correct answer is (a) append().
Explanation: The append() method adds an element to the end of a list in Python. Other methods like insert() can add an element at a specific position, but append() is the most common way to add an element.
Q 47. What is the output of the following Python code?
x = [1, 2, 3]
y = x
y[0] = 10
print(x)
(a) [10, 2, 3]
(b) [1, 2, 3]
(c) Error
(d) [10, 10, 10]
The correct answer is (a) [10, 2, 3].
Explanation: In Python, lists are mutable and are passed by reference. Changing the value of y[0] also changes the value in x because they both refer to the same object in memory.
Q 48. What is the output of the following code?
x = [10, 20, 30, 40]
y = x[1:3]
print(y)
(a) [10, 20]
(b) [20, 30]
(c) [30, 40]
(d) [10, 20, 30, 40]
The correct answer is (b) [20, 30].
Explanation: The slicing operation x[1:3] returns the elements from index 1 to index 2, excluding index 3. Therefore, the result is the list [20, 30].
Q 49. What will be the output of the following Python code?
x = "hello"
x[0] = "H"print(x)
(a) Hello
(b) hello
(c) Error
(d) None
The correct answer is (c) Error.
Explanation: Strings in Python are immutable, meaning that you cannot change an individual character of a string by assignment. The operation x[0] = "H" will result in an error.
Q 50. Which of the following is a correct way to define a function in Python?
(a) function myFunction():
(b) def myFunction[]:
(c) def myFunction():
(d) function myFunction[]
The correct answer is (c) def myFunction():.
Explanation: In Python, functions are defined using the def keyword, followed by the function name and parentheses. The correct syntax is def myFunction():.
Q 51. What will be the output of the following Python code?
x = [1, 2, 3]
y = x * 2
print(y)
(a) [1, 2, 3, 1, 2, 3]
(b) [1, 2, 3, 2, 4, 6]
(c) [1, 2, 3]
(d) Error
The correct answer is (a) [1, 2, 3, 1, 2, 3].
Explanation: In Python, multiplying a list by an integer x * 2 repeats the list. So the list [1, 2, 3] will be repeated twice, resulting in [1, 2, 3, 1, 2, 3].
Q 52. What is the purpose of the "self" keyword in Python?
(a) To reference the current class
(b) To reference the current object
(c) To create a new instance of a class
(d) To define a static method
The correct answer is (b) To reference the current object.
Explanation: The self keyword is used to reference the current instance (object) of a class. It allows you to access attributes and methods of the current object within a class.
Q 53. What will be the output of the following code?
x = {1, 2, 3}
y = {3, 4, 5}
print(x & y)
(a) {1, 2, 3, 4, 5}
(b) {3}
(c) {1, 2}
(d) Error
The correct answer is (b) {3}.
Explanation: The & operator returns the intersection of two sets. In this case, the common element between x and y is 3.
Q 54. What will be the output of the following code?
x = "Python"print(x[1:4])
(a) Pyt
(b) yth
(c) yth
(d) Python
The correct answer is (b) yth.
Explanation: The string slicing x[1:4] returns the characters starting from index 1 up to, but not including, index 4. Therefore, it outputs yth.
Q 55. Which of the following Python keywords is used to define a class?
(a) def
(b) class
(c) function
(d) object
The correct answer is (b) class.
Explanation: The class keyword is used in Python to define a class. The syntax for defining a class is class ClassName:.
Q 56. What is the output of the following Python code?
x = [1, 2, 3, 4]
x.append(5)
print(x)
(a) [1, 2, 3]
(b) [1, 2, 3, 4, 5]
(c) [1, 2, 3, 4]
(d) Error
The correct answer is (b) [1, 2, 3, 4, 5].
Explanation: The append() method adds an element to the end of the list. After calling x.append(5), the list becomes [1, 2, 3, 4, 5].
Q 57. How can you add a comment in Python?
(a) // This is a comment
(b) # This is a comment
(c) /* This is a comment */
(d) -- This is a comment
The correct answer is (b) # This is a comment.
Explanation: In Python, comments are written using the # symbol. Everything after the # on that line is considered a comment and will be ignored during execution.
Q 58. What is the output of the following code?
x = "apple"
y = x.upper()
print(y)
(a) apple
(b) APPLE
(c) Error
(d) None
The correct answer is (b) APPLE.
Explanation: The upper() method converts all characters of the string to uppercase. Therefore, "apple".upper() returns "APPLE".
Q 59. Which of the following is the correct syntax for importing the math module in Python?
(a) import math
(b) from math import *
(c) import math()
(d) include math
The correct answer is (a) import math.
Explanation: The correct syntax to import a module in Python is import math, which makes all functions and variables in the math module available to use.
Q 60. What does the len() function do in Python?
(a) Returns the number of items in an iterable object
(b) Returns the size of an object in bytes
(c) Returns the last element in a list
(d) None of the above
The correct answer is (a) Returns the number of items in an iterable object.
Explanation: The len() function is used to return the number of items in an iterable (like a list, string, or tuple).
Q 61. Which of the following is the correct way to create an empty dictionary in Python?
(a) x = []
(b) x = {}
(c) x = dict()
(d) Both (b) and (c)
The correct answer is (d) Both (b) and (c).
Explanation: You can create an empty dictionary using either curly braces {} or the dict() constructor. Both are valid ways to create an empty dictionary in Python.
Q 62. What is the output of the following code?
x = "Hello, World!"
y = x.replace("World", "Python")
print(y)
(a) Hello, Python!
(b) Hello, World!
(c) Error
(d) None
The correct answer is (a) Hello, Python!.
Explanation: The replace() method replaces a substring within the string with another substring. In this case, "World" is replaced with "Python".
Q 63. What is the purpose of the __init__ method in a Python class?
(a) Initialize class attributes
(b) Initialize instance attributes
(c) Define class methods
(d) Define instance methods
The correct answer is (b) Initialize instance attributes.
Explanation: The __init__ method is a special method in Python classes that is automatically called when an object is created. It is used to initialize instance attributes, making it an essential concept in Python MCQs and Python quiz questions.
Q 64. Which of the following is used to handle exceptions in Python?
(a) try-except block
(b) if-else block
(c) for loop
(d) while loop
The correct answer is (a) try-except block.
Explanation: The try-except block is a key concept in handling exceptions in Python. Understanding exception handling is crucial for Python MCQs with answers and is commonly tested in Python objective questions.
Q 65. How do you open a file in binary mode in Python?
(a) open('filename', 'b')
(b) open('filename', 'rb')
(c) open('filename', 'wb')
(d) open('filename', 'r+b')
The correct answer is (b) open('filename', 'rb').
Explanation: The mode 'rb' stands for read-binary and is used to open files in binary mode. This is a common topic in Python MCQ online tests and Python quiz questions.
Q 66. Which module in Python supports regular expressions?
(a) regex
(b) re
(c) reg
(d) pyreg
The correct answer is (b) re.
Explanation: Python provides the re module to work with regular expressions. Regular expressions are frequently covered in top Python MCQ questions and answers and are useful in text processing.
Q 67. What will be the output of bool([]) in Python?
(a) True
(b) False
(c) None
(d) Error
The correct answer is (b) False.
Explanation: An empty list is considered False in Python when used in a boolean context. This is commonly asked in Python MCQs and Python quiz questions.
Q 68. Which of the following is NOT a valid Python variable name?
(a) my_var
(b) _var123
(c) 123var
(d) var_1
The correct answer is (c) 123var.
Explanation: Variable names cannot start with a number in Python. This is a key concept in Python MCQ questions and Python interview quizzes.
Q 69. What does the super() function do in Python?
(a) Calls the parent class constructor
(b) Calls a static method
(c) Deletes an object
(d) Terminates the program
The correct answer is (a) Calls the parent class constructor.
Explanation: The super() function is used to call methods from a parent class in inheritance. This is frequently tested in advanced Python MCQs and Python coding quizzes.
Q 70. What is the output of type(lambda x: x) in Python?
(a) function
(b) lambda
(c) method
(d) None of the above
The correct answer is (a) function.
Explanation: In Python, a lambda function is of type function. This is an important topic in Python MCQs with answers and Python quizzes.
Q 71. What does the ord() function do in Python?
(a) Converts a string to uppercase
(b) Returns the Unicode code of a character
(c) Converts a number to a string
(d) Returns the ASCII value of a number
The correct answer is (b) Returns the Unicode code of a character.
Explanation: The ord() function returns the Unicode code of a given character. This is commonly asked in Python MCQs for competitive exams.
Q 72. Which method is used to remove whitespace from the beginning and end of a string in Python?
(a) strip()
(b) trim()
(c) remove()
(d) erase()
The correct answer is (a) strip().
Explanation: The strip() method removes whitespace from both ends of a string. It is a frequently tested topic in Python interview MCQs.
Q 73. What will be the output of print(2 ** 3 ** 2) in Python?
(a) 64
(b) 512
(c) 8
(d) 256
The correct answer is (b) 512.
Explanation: The expression evaluates as 2 ** (3 ** 2), which is 2 ** 9 = 512. This concept is often tested in Python MCQ online tests.
Q 74. Which function is used to get the current working directory in Python?
(a) os.getcwd()
(b) os.pwd()
(c) os.cwd()
(d) os.getpwd()
The correct answer is (a) os.getcwd().
Explanation: The os.getcwd() function returns the current working directory. It is a common question in Python MCQs and Python coding quizzes.
Q 75. What will be the output of print(list("python"))?
(a) ['python']
(b) ['p', 'y', 't', 'h', 'o', 'n']
(c) ['p y t h o n']
(d) Error
The correct answer is (b) ['p', 'y', 't', 'h', 'o', 'n'].
Explanation: The list() function converts a string into a list of characters.
Q 76. Which of the following is used to read a file line by line in Python?
(a) readlines()
(b) read()
(c) readline()
(d) Both (a) and (c)
The correct answer is (d) Both (a) and (c).
Explanation: The readlines() method reads all lines of a file into a list, while readline() reads one line at a time.
Q 77. How do you create a tuple with a single element?
(a) (5)
(b) (5,)
(c) (5, 5)
(d) tuple(5)
The correct answer is (b) (5,).
Explanation: A trailing comma is required to differentiate a tuple from a simple integer expression.
Q 78. What will be the output of sorted([3, 1, 4, 1, 5, 9], reverse=True)?
(a) [1, 1, 3, 4, 5, 9]
(b) [9, 5, 4, 3, 1, 1]
(c) [3, 1, 4, 1, 5, 9]
(d) None of the above
The correct answer is (b) [9, 5, 4, 3, 1, 1].
Explanation: The sorted() function sorts the list in descending order when reverse=True is specified.
Q 79. Which module is used to generate random numbers in Python?
(a) random
(b) randint
(c) math
(d) rand
The correct answer is (a) random.
Explanation: The random module provides functions to generate random numbers.
Q 80. Which keyword is used to define a generator in Python?
(a) yield
(b) return
(c) generate
(d) def
The correct answer is (a) yield.
Explanation: The yield keyword is used inside a function to create a generator.
Q 81. What is the difference between is and == in Python?
(a) No difference
(b)is checks identity, == checks value
(c)is checks value, == checks reference
(d) None of the above
The correct answer is (b) is checks identity, == checks value.
Explanation: The is operator checks whether two variables refer to the same object in memory, while == checks if their values are equal.
Q 82. What will be the output of print(0.1 + 0.2 == 0.3)?
(a) True
(b) False
(c) Error
(d) None
The correct answer is (b) False.
Explanation: Due to floating-point precision issues, 0.1 + 0.2 is not exactly equal to 0.3.
Q 83. What will be the output of print(type(lambda x: x)) in Python?
(a) function
(b) lambda
(c) class
(d) None
The correct answer is (a) function.
Explanation: A lambda function in Python is an anonymous function and its type is function.
Q 84. Which method is used to remove an item from a dictionary by key and return its value?
(a) remove()
(b) discard()
(c) pop()
(d) del
The correct answer is (c) pop().
Explanation: The pop() method removes the specified key and returns its value.
Q 85. What will be the output of print(bool(0), bool(1), bool(-1))?
(a) True True True
(b) False True True
(c) False False True
(d) True False False
The correct answer is (b) False True True.
Explanation: In Python, 0 evaluates to False, while any nonzero number (positive or negative) evaluates to True.
Q 86. What is the output of print('Python'.replace('y', 'i'))?
(a) Pithon
(b) Python
(c) Pithin
(d) Pithoni
The correct answer is (a) Pithon.
Explanation: The replace() method replaces occurrences of a specified character in a string.
Q 87. Which of the following data structures supports key-value pairs?
(a) List
(b) Tuple
(c) Dictionary
(d) Set
The correct answer is (c) Dictionary.
Explanation: A dictionary in Python stores key-value pairs, making it suitable for fast lookups.
Q 88. What will be the output of print(2 ** 3 ** 2)?
(a) 512
(b) 64
(c) 256
(d) 8
The correct answer is (a) 512.
Explanation: Python evaluates exponentiation from right to left, so 3 ** 2 is 9, and 2 ** 9 is 512.
Q 89. Which Python function is used to get the ASCII value of a character?
(a) ord()
(b) chr()
(c) ascii()
(d) ord_ascii()
The correct answer is (a) ord().
Explanation: The ord() function returns the ASCII value of a given character.
Q 90. What will be the output of bool([]), bool([0]), bool(None)?
(a) False, False, False
(b) False, True, False
(c) True, True, False
(d) True, False, True
The correct answer is (b) False, True, False.
Explanation: An empty list and None evaluate to False, while a non-empty list (even with 0) evaluates to True.
Q 91. What does enumerate() function in Python return?
(a) A dictionary
(b) A tuple containing index and value
(c) A set
(d) A single integer
The correct answer is (b) A tuple containing index and value.
Explanation: The enumerate() function returns an iterable that produces index-value pairs from a sequence.
Q 92. What is the primary difference between deepcopy() and copy() in Python?
(a)deepcopy() copies objects recursively
(b)copy() creates a completely new object
(c)deepcopy() is faster than copy()
(d) There is no difference
The correct answer is (a) deepcopy() copies objects recursively.
Explanation: The deepcopy() method creates independent copies of nested objects, while copy() only makes a shallow copy.
Q 93. What will be the output of print(type(lambda x: x))?
(a) <class 'function'>
(b) <class 'lambda'>
(c) <class 'method'>
(d) SyntaxError
The correct answer is (a) <class 'function'>.
Explanation: In Python, a lambda function is treated as a regular function and has the type 'function'.
Q 94. Which of the following is the correct syntax to check if a key exists in a dictionary?
(a) if key in dict
(b) if dict.has_key(key)
(c) if key.exists(dict)
(d) if key is dict
The correct answer is (a) if key in dict.
Explanation: The correct way to check if a key exists in a dictionary is using if key in dict.
Q 95. What will be the output of print(bool('False'))?
(a) False
(b) True
(c) Error
(d) None
The correct answer is (b) True.
Explanation: Any non-empty string, including 'False', evaluates to True in Python.
Q 96. Which of the following methods can be used to remove an element from a set in Python?
(a) remove()
(b) discard()
(c) pop()
(d) All of the above
The correct answer is (d) All of the above.
Explanation: The remove() method removes an item but raises an error if it doesn't exist, discard() removes without error, and pop() removes a random element.
Q 97. What is the correct way to open a file in Python for both reading and writing?
(a) open('file.txt', 'rw')
(b) open('file.txt', 'r+')
(c) open('file.txt', 'w+')
(d) Both (b) and (c)
The correct answer is (d) Both (b) and (c).
Explanation: The 'r+' mode allows reading and writing without truncating the file, while 'w+' also allows both operations but erases the file first.
Q 98. What will be the output of print(2 ** 3 ** 2)?
(a) 64
(b) 512
(c) 36
(d) 8
The correct answer is (b) 512.
Explanation: The exponentiation operator ** is evaluated from right to left. So, 3 ** 2 is 9, and 2 ** 9 is 512.
Q 99. What is the output of print(list(range(3, 15, 3)))?
(a) [3, 6, 9, 12]
(b) [3, 6, 9]
(c) [3, 6, 9, 12, 15]
(d) Error
The correct answer is (a) [3, 6, 9, 12].
Explanation: The range() function generates numbers from 3 to 14 (excluding 15) with a step of 3, so the output is [3, 6, 9, 12].
Q 100. What does the zip() function do in Python?
(a) Combines multiple lists element-wise into tuples
(b) Sorts a list
(c) Compresses data
(d) Merges two dictionaries
The correct answer is (a) Combines multiple lists element-wise into tuples.
Explanation: The zip() function pairs corresponding elements from multiple iterables into tuples, creating a new iterable.
Conclusion
In conclusion, practicing Python MCQ questions is an excellent way to reinforce your understanding of core Python concepts and prepare for exams or interviews. By regularly solving Python MCQs, you can improve your problem-solving skills and become more proficient in the language. Whether you're a beginner or an advanced learner, Python MCQs provide a valuable resource for mastering Python programming.
Dear learners, join our Tech Trendy Masterclasses to help you to learn and immerse yourself in the latest trending technologies and upgrade your tech skills with the latest skills trends, design, and practices.
The GIL is a mutex that allows only one thread to execute Python bytecode at a time, limiting multi-threading performance.
External libraries can be installed using the pip package manager, e.g., pip install library_name.
The pass statement is a no-operation statement in Python. It is used when a statement is syntactically required but no code needs to be executed, such as when defining an empty function or class.
Python handles memory management automatically through reference counting and garbage collection. Objects are created in a private heap, and the garbage collector frees up unused memory when objects are no longer in use.
Mutable objects can be modified after creation, e.g., list, dict, set.
Immutable objects cannot be changed once created, e.g., int, float, str, tuple.
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)
Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.
Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.