Python MCQ questions are a great way to learn and test your Python skills. These questions cover important topics like syntax, functions, loops, and more, helping you prepare for exams, interviews, or practice. Multiple-choice questions are quick to answer and give instant feedback, making them an effective tool for improving your understanding of Python. Whether you are a beginner or an experienced programmer, solving Python MCQs regularly can boost your confidence and highlight areas that need more focus. They are also helpful for getting familiar with Python concepts in a structured and easy-to-follow format.
55 Python MCQ Questions for Beginners
- What is the output of print(“Hello, World!”)?
- a) Hello World!
- b) Hello, World!
- c) Error
- d) None
Answer: b) Hello, World!
- Which symbol is used to start a comment in Python?
- a) //
- b) <!–
- c) #
- d) /*
Answer: c) #
- What is the correct extension of a Python file?
- a) .py
- b) .python
- c) .pt
- d) .pyt
Answer: a) .py
- What is the output of type(10) in Python?
- a) int
- b) float
- c) str
- d) complex
Answer: a) int
- Which of the following is a mutable data type in Python?
- a) Tuple
- b) String
- c) List
- d) None of the above
Answer: c) List - What will be the output of the following code?
if 5 > 2:
print(“Yes”)
- a) Error
- b) Yes
- c) None
- d) 5 > 2
Answer: b) Yes
- What keyword is used to skip an iteration of a loop?
- a) pass
- b) skip
- c) continue
- d) break
Answer: c) continue
- How do you define a function in Python?
- a) function myFunc():
- b) def myFunc():
- c) myFunc():
- d) func myFunc():
Answer: b) def myFunc():
- What will len([1, 2, 3, 4]) return?
- a) 4
- b) 5
- c) Error
- d) None
Answer: a) 4
- Which keyword is used to create a class in Python?
- a) class
- b) def
- c) struct
- d) object
Answer: a) class
- In Python, what is self in a class?
- a) A reference to the current class
- b) A reference to the parent class
- c) A local variable
- d) None of the above
Answer: a) A reference to the current class
- What mode opens a file for both reading and writing?
- a) r
- b) w+
- c) a
- d) rw
Answer: b) w+
- What keyword is used to handle exceptions in Python?
- a) exception
- b) try
- c) catch
- d) handle
Answer: b) try
- Which exception is raised when dividing by zero?
- a) ValueError
- b) ZeroDivisionError
- c) ArithmeticError
- d) TypeError
Answer: b) ZeroDivisionError
- What is the output of the following code?
print(bool(0), bool(1)) - a) True True
- b) False True
- c) True False
- d) False False
Answer: b) False True
- Which method is used to add an element to a list?
- a) insert()
- b) append()
- c) add()
- d) push()
Answer: b) append()
- How is a tuple different from a list in Python?
- a) Tuples are mutable, lists are immutable
- b) Tuples use parentheses, lists use square brackets
- c) Lists cannot contain duplicate elements, tuples can
- d) Tuples are faster to access than lists
Answer: b) Tuples use parentheses, lists use square brackets
- What will be the output of the following code?
x = [1, 2, 3]
print(x * 2)
- a) [1, 2, 3]
- b) [1, 2, 3, 1, 2, 3]
- c) [2, 4, 6]
- d) Error
Answer: b) [1, 2, 3, 1, 2, 3]
- How do you create an empty dictionary in Python?
- a) []
- b) {}
- c) ()
- d) dict()
Answer: d) dict()
- What does id() function in Python return?
- a) The type of the variable
- b) The identity of the variable
- c) The length of the variable
- d) The memory address of the variable
Answer: d) The memory address of the variable
- What is the output of the following code?
a = {1, 2, 3}
b = {3, 4, 5}
print(a & b)
- a) {1, 2}
- b) {3}
- c) {1, 2, 3, 4, 5}
- d) Error
Answer: b) {3}
- Which method is used to convert a string to lowercase?
- a) lowerCase()
- b) lowercase()
- c) lower()
- d) toLowerCase()
Answer: c) lower()
- What is the output of the following code?
for i in range(1, 5):
print(i, end=”, “)
- a) 1, 2, 3, 4,
- b) 1 2 3 4
- c) 1, 2, 3, 4
- d) Error
Answer: a) 1, 2, 3, 4,
- What is the purpose of the __init__ method in Python classes?
- a) To initialize a class variable
- b) To create an object of the class
- c) To initialize an instance of the class
- d) To define class-level methods
Answer: c) To initialize an instance of the class
- Which of the following data structures is ordered?
- a) Set
- b) Dictionary
- c) List
- d) Both b and c
Answer: c) List
- What will be the output of the following code?
print(2 ** 3 ** 2) - a) 64
- b) 512
- c) 16
- d) Error
Answer: b) 512
- What does the is operator compare?
- a) Values of two objects
- b) Data types of two objects
- c) Memory location of two objects
- d) Length of two objects
Answer: c) Memory location of two objects
- Which function is used to get the current working directory in Python?
- a) getcwd()
- b) getwd()
- c) curdir()
- d) path.cwd()
Answer: a) os.getcwd()
- How do you create a new set in Python?
- a) set[]
- b) {}
- c) set()
- d) set()
Answer: c) set()
- Which library is used for data manipulation in Python?
- a) Matplotlib
- b) Pandas
- c) NumPy
- d) SciPy
Answer: b) Pandas
- What does the np.array() function do in NumPy?
- a) Creates a new array
- b) Deletes an array
- c) Splits an array
- d) Joins arrays
Answer: a) Creates a new array
- What is the purpose of plt.show() in Matplotlib?
- a) To close a plot
- b) To display a plot
- c) To save a plot
- d) To edit a plot
Answer: b) To display a plot
- Which Python library is commonly used for scientific computations?
- a) Scikit-learn
- b) NumPy
- c) BeautifulSoup
- d) Flask
Answer: b) NumPy
- What is the output of np.zeros((2,2)) in NumPy?
- a) A 2×2 matrix with all elements as 0
- b) A 2×2 matrix with all elements as 1
- c) A 1D array with two elements
- d) Error
Answer: a) A 2×2 matrix with all elements as 0
- What is the result of the expression 10 // 3?
- a) 3.33
- b) 3
- c) 4
- d) None
Answer: b) 3
- Which of the following is not a Python keyword?
- a) assert
- b) with
- c) lambda
- d) eval
Answer: d) eval
- What does the zip() function do?
- a) Combines two iterables into a single iterable
- b) Compresses a file
- c) Returns the length of an iterable
- d) None of the above
Answer: a) Combines two iterables into a single iterable
- Which function is used to sort a list in Python?
- a) sort()
- b) sorted()
- c) order()
- d) Both a and b
Answer: d) Both a and b
- What is the output of round(4.567, 2)?
- a) 4.57
- b) 4.56
- c) 4.6
- d) None
Answer: a) 4.57
- What does re.match() do in Python?
- a) Searches for a match anywhere in the string
- b) Finds all matches in the string
- c) Matches only at the beginning of the string
- d) None of the above
Answer: c) Matches only at the beginning of the string
- What will be the result of the following code?
a = [1, 2, 3]
print(a[3:])
- a) []
- b) [3]
- c) Error
- d) None
Answer: a) []
- What is the purpose of the @staticmethod decorator in Python?
- a) Defines a method that belongs to the instance
- b) Defines a method that belongs to the class but does not access class or instance variables
- c) Defines a private method
- d) Defines an abstract method
Answer: b) Defines a method that belongs to the class but does not access class or instance variables
- What does the following code do?
print(“,”.join([“a”, “b”, “c”])) - a) Prints a b c
- b) Prints abc
- c) Prints a,b,c
- d) None of the above
Answer: c) Prints a,b,c
- What is the default value returned by a Python function that does not specify a return value?
- a) 0
- b) None
- c) Null
- d) False
Answer: b) None
- Which operator is used for matrix multiplication in Python (Python 3.5+)?
- a) *
- b) matmul
- c) @
- d) multiply
Answer: c) @
- What keyword is used to define a generator in Python?
- a) yield
- b) return
- c) generator
- d) generate
Answer: a) yield
- What does the next() function do in Python?
- a) Terminates an iteration
- b) Returns the next item from an iterator
- c) Moves to the next function in a script
- d) None of the above
Answer: b) Returns the next item from an iterator
- Which method is called when an iterator reaches the end of the data?
- a) StopIteration
- b) KeyError
- c) IndexError
- d) ValueError
Answer: a) StopIteration
- How do you create an iterator in Python?
- a) Use the iter() function
- b) Define a class with __next__() and __iter__() methods
- c) Use a generator
- d) All of the above
Answer: d) All of the above
- What is the difference between return and yield in Python?
- a) return terminates a function; yield pauses it and saves its state
- b) return is used in loops; yield is used in classes
- c) yield is faster than return
- d) None of the above
Answer: a) return terminates a function; yield pauses it and saves its state
- What does the re.search() function do?
- a) Matches a pattern at the start of a string
- b) Searches for a pattern anywhere in the string
- c) Returns all matches in a string
- d) None of the above
Answer: b) Searches for a pattern anywhere in the string
- Which character is used to indicate zero or more occurrences in a regex pattern?
- a) ?
- b) *
- c) +
- d) $
Answer: b) *
- What does the ^ character signify in regex?
- a) Matches any character except a newline
- b) Matches at the start of a string
- c) Matches at the end of a string
- d) Escapes a special character
Answer: b) Matches at the start of a string
- How do you match a digit in regex?
- a) \s
- b) \d
- c) \w
- d) \D
Answer: b) \d
- What is the output of the following regex?
import re
result = re.match(r”\d+”, “123abc”)
print(result.group())
- a) 123
- b) abc
- c) Error
- d) None
Answer: a) 123
Wrapping Up
Practicing Python MCQ questions is an excellent way to enhance your programming skills and prepare for exams or interviews. These questions cover a variety of topics, including data types, loops, functions, and advanced concepts like object-oriented programming. Regular practice with Python MCQ questions helps reinforce your understanding, identify knowledge gaps, and improve problem-solving abilities. Whether you’re a beginner or an experienced programmer, these questions provide valuable insights into Python’s core principles. Remember, consistency is key. Keep solving MCQs to stay sharp, build confidence, and excel in Python. The more you practice, the better prepared you’ll be for challenges.