Python MCQs are an excellent way to test and strengthen your understanding of this versatile programming language. From beginners to professionals, they help assess knowledge of Python's syntax, functions, and applications. This article provides a curated collection of Python MCQs to enhance your learning and boost your confidence. Dive in to explore key concepts and prepare effectively for exams or interviews!
In this Interview Tutorial, let's learn the most commonly asked Python MCQs.
Top 50 + Python MCQ Questions and Answers
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".
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.