11 Sep 100 Python MCQ (Multiple Choice Questions) with Answers
1) What is the correct extension of a Python file?
Show Answer
Answer: c
Explanation
Python source files use the .py extension, for example
script.py.2) Who created the Python programming language?
Show Answer
Answer: a
Explanation
Python was created by Guido van Rossum and first released in 1991.
3) Which of the following is the correct syntax to output “Hello World” in Python?
Show Answer
Answer: b
Explanation
The built-in
print() function displays output in Python: print("Hello World").4) How do you insert comments in Python code?
Show Answer
Answer: c
Explanation
Single-line comments in Python begin with the # symbol.
5) Which data type is immutable in Python?
Show Answer
Answer: d
Explanation
A tuple is immutable — its contents cannot be changed after creation. Lists, dictionaries and sets are mutable.
6) What is the result of 3 ** 2 in Python?
Show Answer
Answer: b
Explanation
The
** operator means exponentiation. So 3 ** 2 means 3² = 9.7) Which keyword is used to define a function in Python?
Show Answer
Answer: c
Explanation
Functions are defined using the
def keyword, e.g. def my_function():.8) Which of the following operators performs integer division in Python?
Show Answer
Answer: b
Explanation
// performs floor/integer division. For example, 7 // 2 gives 3.9) What is the output of len([10, 20, 30])?
Show Answer
Answer: b
Explanation
The list contains three elements, so
len([10, 20, 30]) returns 3.10) How do you create a variable with the numeric value 5?
Show Answer
Answer: d
Explanation
Both
x = 5 and x = int(5) create a variable with numeric value 5.11) Which collection is ordered, changeable, and allows duplicate members?
Show Answer
Answer: d
Explanation
A list is ordered, mutable/changeable, and allows duplicate elements.
12) Which collection is unordered, unchangeable, and unindexed?
Show Answer
Answer: a
Explanation
A set is unordered and unindexed. Its items are not accessed by index and duplicates are not allowed.
13) What function is used to convert a value into an integer?
Show Answer
Answer: c
Explanation
The
int() function converts a compatible value into an integer.14) What will type(3.14) return?
Show Answer
Answer: b
Explanation
3.14 is a floating-point number, so type(3.14) returns <class 'float'>.15) How do you start a for loop in Python?
Show Answer
Answer: a
Explanation
Python uses the
for x in y: syntax to iterate over items in an iterable.16) Which method is used to remove whitespace from both the beginning and end of a string?
Show Answer
Answer: c
Explanation
strip() removes leading and trailing whitespace from a string.17) What keyword is used to raise an exception in Python?
Show Answer
Answer: b
Explanation
The
raise keyword is used to manually raise an exception in Python.18) What is the correct syntax for an if statement in Python?
Show Answer
Answer: c
Explanation
Python uses
if condition: and == for comparison. The colon at the end is required.19) Which operator is used to check if two values are equal?
Show Answer
Answer: b
Explanation
== checks equality of values. = is assignment, and is checks object identity.20) What is the output of bool(“”)?
Show Answer
Answer: b
Explanation
An empty string is considered falsey in Python, so
bool("") returns False.21) Which method adds an item to the end of a list?
Show Answer
Answer: b
Explanation
append() adds a single item to the end of a list.22) How do you access the value associated with the key “age” in dictionary d?
Show Answer
Answer: b
Explanation
Dictionary values are accessed using square brackets with the key, e.g.
d["age"].23) What statement is used to exit a loop prematurely?
Show Answer
Answer: c
Explanation
The
break statement immediately exits the nearest enclosing loop.24) Which built-in function returns a range of numbers?
Show Answer
Answer: b
Explanation
range() generates a sequence of numbers, commonly used in for loops.25) What is the logical operator for logical AND in Python?
Show Answer
Answer: b
Explanation
Python uses the keyword
and for logical AND, not &&.26) Which symbol is used to pass variable-length positional arguments to a function?
Show Answer
Answer: a
Explanation
*args collects extra positional arguments into a tuple.27) Which keyword is used to create a class in Python?
Show Answer
Answer: c
Explanation
Classes are created using the
class keyword, e.g. class MyClass:.28) What will 2 + 3 * 4 evaluate to?
Show Answer
Answer: b
Explanation
Multiplication has higher precedence than addition:
3 * 4 = 12, then 2 + 12 = 14.29) What is the output of “python”[1:4]?
Show Answer
Answer: b
Explanation
Slicing
[1:4] returns characters at indices 1, 2 and 3: y, t, h → yth.30) How do you create an empty dictionary in Python?
Show Answer
Answer: a
Explanation
{} creates an empty dictionary. [] is a list, () is a tuple and set() is an empty set.31) What keyword handles exceptions in Python?
Show Answer
Answer: b
Explanation
Python uses
try and except blocks to catch and handle exceptions.32) Which built-in function returns the highest value in a list?
Show Answer
Answer: b
Explanation
max() returns the largest item in an iterable or among arguments.33) What is the output of type([])?
Show Answer
Answer: d
Explanation
[] creates a list, so type([]) returns <class 'list'>.34) What keyword is used to import a module in Python?
Show Answer
Answer: a
Explanation
Use
import module_name to import a module in Python.35) What is the default return value of a function that doesn’t explicitly return anything?
Show Answer
Answer: c
Explanation
If a function has no
return statement, Python returns None by default.36) Which method converts a string to all uppercase letters?
Show Answer
Answer: b
Explanation
upper() returns a copy of the string converted to uppercase.37) How do you remove an item at a specific index from a list?
Show Answer
Answer: c
Explanation
pop(index) removes and returns the item at the given index.38) What does PIP stand for in Python?
Show Answer
Answer: a
Explanation
PIP is commonly expanded as Preferred Installer Program and is used to install Python packages.
39) Which operator is used for exponentiation?
Show Answer
Answer: b
Explanation
The
** operator raises a number to a power, e.g. 2 ** 3 = 8.40) What is the output of bool(0)?
Show Answer
Answer: b
Explanation
Zero is falsey in Python, so
bool(0) returns False.41) Which statement skips the current iteration of a loop and continues with the next?
Show Answer
Answer: c
Explanation
continue skips the rest of the current iteration and moves to the next iteration of the loop.42) What function returns the absolute value of a number?
Show Answer
Answer: b
Explanation
abs() returns the absolute value of a number, e.g. abs(-5) is 5.43) Which special variable represents the class instance in class methods?
Show Answer
Answer: b
Explanation
By convention,
self refers to the current instance of the class inside instance methods.44) What is the output of “hello”.find(“l”)?
Show Answer
Answer: a
Explanation
"hello".find("l") returns the index of the first l, which is 2 (0-based indexing).45) Which data structure stores keys and values?
Show Answer
Answer: c
Explanation
A dictionary stores data as key-value pairs, e.g.
{"name": "Alice", "age": 25}.46) How do you create an anonymous or inline function in Python?
Show Answer
Answer: b
Explanation
lambda creates a small anonymous function, e.g. lambda x: x + 1.47) What method removes all items from a dictionary?
Show Answer
Answer: c
Explanation
clear() removes all key-value pairs from a dictionary, leaving it empty.48) What is the output of 10 % 3?
Show Answer
Answer: b
Explanation
% is the modulo operator. 10 % 3 gives the remainder 1.49) Which method converts a list of strings into a single string separated by a delimiter?
Show Answer
Answer: b
Explanation
join() combines a list of strings using a specified delimiter, e.g. "-".join(["a", "b"]).50) What is the result of str(123)?
Show Answer
Answer: b
Explanation
str(123) converts the integer 123 into the string '123'.51) How do you open a file named “test.txt” for reading in Python?
Show Answer
Answer: a
Explanation
The mode
"r" opens a file for reading: open("test.txt", "r").52) What method splits a string into a list of substrings?
Show Answer
Answer: b
Explanation
split() breaks a string into a list of substrings based on a delimiter.53) Which keyword is used to test if a sequence contains a specific item?
Show Answer
Answer: a
Explanation
Use
in to test membership, e.g. 3 in [1, 2, 3] returns True.54) What is the output of list(range(3))?
Show Answer
Answer: c
Explanation
range(3) produces 0, 1, 2, so converting it to a list gives [0, 1, 2].55) Which error occurs when a variable is used before it is defined?
Show Answer
Answer: c
Explanation
Using an undefined variable raises a NameError in Python.
56) What does “is” operator evaluate?
Show Answer
Answer: b
Explanation
is checks whether two references point to the same object in memory, not just equal values.57) What is the output of “a” + “b”?
Show Answer
Answer: a
Explanation
The
+ operator concatenates strings, so "a" + "b" gives "ab".58) How do you get the last item of a list lst?
Show Answer
Answer: b
Explanation
Negative indexing works from the end, so
lst[-1] returns the last item.59) Which block is always executed whether an exception occurs or not?
Show Answer
Answer: d
Explanation
The
finally block always runs, whether an exception occurred or not.60) What keyword creates a generator function?
Show Answer
Answer: b
Explanation
A function containing
yield returns a generator, producing values lazily one at a time.61) What is the output of min([5, 2, 8, 1])?
Show Answer
Answer: d
Explanation
min() returns the smallest value, which is 1.62) Which method adds all elements of an iterable to a list?
Show Answer
Answer: b
Explanation
extend() adds each element from an iterable to the end of a list.63) What will set([1, 2, 2, 3]) yield?
Show Answer
Answer: b
Explanation
A set removes duplicates, so
{1, 2, 2, 3} becomes {1, 2, 3}.64) Which module in Python provides tools for working with regular expressions?
Show Answer
Answer: b
Explanation
The built-in
re module provides regular expression matching operations.65) What is the correct syntax for a list comprehension that doubles each element in nums?
Show Answer
Answer: a
Explanation
A list comprehension follows the form
[expression for item in iterable], so [x * 2 for x in nums] is correct.66) What function returns the length of an object?
Show Answer
Answer: c
Explanation
len() returns the number of items in an object such as a string, list, tuple or dictionary.67) What is the output of bool(None)?
Show Answer
Answer: b
Explanation
None is falsey, so bool(None) returns False.68) How do you convert a string to lowercase?
Show Answer
Answer: a
Explanation
lower() returns a copy of the string converted to lowercase.69) Which method reverses a list in place?
Show Answer
Answer: a
Explanation
reverse() reverses the list in place. reversed() returns an iterator instead.70) What is the result of “Python”[::-1]?
Show Answer
Answer: b
Explanation
The slice
[::-1] reverses the string, so "Python"[::-1] gives nohtyP.71) Which operator is used for bitwise AND?
Show Answer
Answer: b
Explanation
& performs bitwise AND. and is the logical AND operator.72) What built-in module gives access to math functions like sqrt and sin?
Show Answer
Answer: a
Explanation
The
math module provides functions such as sqrt(), sin(), cos() and constants like pi.73) What is the primary constructor method for a Python class?
Show Answer
Answer: b
Explanation
__init__() is the initializer/constructor method called automatically when a new instance is created.74) What is the result of float(5)?
Show Answer
Answer: b
Explanation
float(5) converts the integer 5 to the floating-point number 5.0.75) What does the pass statement do?
Show Answer
Answer: c
Explanation
pass is a null statement. It does nothing and is used as a placeholder where code is syntactically required.76) How do you pass keyword-based variable arguments to a function?
Show Answer
Answer: b
Explanation
**kwargs collects extra keyword arguments into a dictionary.77) What exception is raised when dividing by zero?
Show Answer
Answer: b
Explanation
Division by zero raises a ZeroDivisionError in Python.
78) Which built-in function pairs elements from two or more iterables?
Show Answer
Answer: b
Explanation
zip() combines elements from multiple iterables into tuples, stopping at the shortest iterable.79) What will all([True, True, False]) evaluate to?
Show Answer
Answer: b
Explanation
all() returns True only if every element is true. Since one element is False, the result is False.80) What will any([False, True, False]) evaluate to?
Show Answer
Answer: a
Explanation
any() returns True if at least one element is true. Since one element is True, the result is True.81) What is the output of 3 == 3.0?
Show Answer
Answer: a
Explanation
In Python,
3 == 3.0 is True because their numeric values are equal.82) How do you delete a variable in Python?
Show Answer
Answer: b
Explanation
The
del statement deletes a variable reference, e.g. del x.83) Which statement opens a file and automatically closes it when finished?
Show Answer
Answer: c
Explanation
The
with open("file") as f: statement ensures the file is automatically closed after use.84) What is the output of “Hello, World!”.startswith(“Hello”)?
Show Answer
Answer: a
Explanation
startswith("Hello") returns True because the string begins with “Hello”.85) What does isinstance(5, int) return?
Show Answer
Answer: b
Explanation
isinstance(5, int) checks whether 5 is an instance of int, which is True.86) What is the value of x after x = 10; x += 5?
Show Answer
Answer: c
Explanation
x += 5 is equivalent to x = x + 5, so 10 + 5 = 15.87) How do you copy a list lst without modifying the original?
Show Answer
Answer: d
Explanation
lst.copy(), lst[:] and list(lst) all create a shallow copy of the list.88) What method inserts an element at a specific index in a list?
Show Answer
Answer: c
Explanation
insert(index, item) inserts an item at the specified index in a list.89) What module provides access to command-line arguments?
Show Answer
Answer: b
Explanation
The
sys module exposes command-line arguments through sys.argv.90) What is the output of “Py” * 3?
Show Answer
Answer: b
Explanation
String repetition with
* repeats the string, so "Py" * 3 gives PyPyPy.91) Which error occurs when a key is not found in a dictionary?
Show Answer
Answer: c
Explanation
Accessing a missing dictionary key raises a KeyError.
92) What function takes a function and an iterable and applies the function to all items?
Show Answer
Answer: b
Explanation
map(function, iterable) applies the function to every item in the iterable.93) What function filters elements from an iterable based on a condition function?
Show Answer
Answer: a
Explanation
filter(function, iterable) keeps only the items for which the function returns True.94) What is the output of round(3.57, 1)?
Show Answer
Answer: b
Explanation
round(3.57, 1) rounds to one decimal place, giving 3.6.95) Which method returns a dictionary’s keys as a view object?
Show Answer
Answer: b
Explanation
dict.keys() returns a view object containing the dictionary’s keys.96) What is the output of bool([0])?
Show Answer
Answer: b
Explanation
A non-empty list is truthy even if it contains
0, so bool([0]) returns True.97) How do you import only the pi constant from the math module?
Show Answer
Answer: b
Explanation
from math import pi imports only the pi constant from the math module.98) What built-in method converts a list to a tuple?
Show Answer
Answer: a
Explanation
tuple() converts an iterable such as a list into a tuple.99) What does the enumerate() function return?
Show Answer
Answer: c
Explanation
enumerate() returns index-element pairs, usually as tuples, while iterating.100) What is the output of sum([1, 2, 3, 4])?
Show Answer
Answer: a
Explanation
sum([1, 2, 3, 4]) adds the numbers: 1 + 2 + 3 + 4 = 10.
No Comments