PYTHON MCQ QUESTIONS BASED ON THE BELOW TOPICS
1. Data types, operators, keywords
2. String-indexing, slicing, methods, functions
3. List- indexing, slicing, methods, functions
4. Tuple- indexing, slicing, methods, functions
5. Dictionary- keys, value, methods, functions
6. Module: random, collections(counter, OrderedDict, defaultdict)
Data types, operators, keywords
1. Data Types, Operators, and Keywords MCQs
Q1: What will be the output of type(10.5) in Python?
a) int
b) float ✅
c) double
d) long
Q2: Which of the following data types is immutable in Python?
a) list
b) dictionary
c) tuple ✅
d) set
Q3: What is the correct operator for floor division in Python?
a) /
b) // ✅
c) %
d) **
Q4: What will be the output of 5 % 3?
a) 1 ✅
b) 2
c) 3
d) 0
Q5: Which of the following is NOT a keyword in Python?
a) pass
b) lambda
c) function ✅
d) return
Q6: What will be the output of bool(0)?
a) True
b) False ✅
c) None
d) 0
Q7: Which operator is used for exponentiation (power) in Python?
a) ^
b) ** ✅
c) //
d) pow
Q8: What is the result of 10 > 5 and 5 < 3?
a) True
b) False ✅
c) None
d) Error
✅
Q9: Which of the following is a valid Python keyword?
a) finally
b) define
c) exit
d) loop
Q10: What will be the output of 10 / 3 in Python?
a) 3
b) 3.0
c) 3.3333 ✅
d) 3.33
String-indexing, slicing, methods, functions
Q1: What is the output of the following code?
python
CopyEdit
s = "Python"
print(s[2])
a) P
b) y
c) t ✅
d) h
Q2: What will s[-1] return for s = "Hello"?
a) H
b) o ✅
c) e
d) l
Q3: What will be the output of s[1:4] for s = "Python"?
a) Pyt
b) yth
c) ytho
d) yth ✅
Q4: Which method converts a string to uppercase?
a) upper() ✅
b) capitalize()
c) lower()
d) title()
Q5: What does "hello".replace("l", "z") return?
a) hezzo ✅
b) hezo
c) hello
d) hezlo
Q6: What does "Python".find("y") return?
a) 0
b) 1 ✅
c) 2
d) -1
Q7: What is the output of len("Python")?
a) 5
b) 6 ✅
c) 7
d) Error
Q8: What will "hello world".split() return?
a) ['hello world']
b) ['hello', 'world'] ✅
c) ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
d) ('hello', 'world')
Q9: What is the result of "Hello".startswith("He")?
a) True ✅
b) False
c) None
d) Error
Q10: Which of the following is not a valid string method?
a) isalnum()
b) isdigit()
c) isnumber() ✅
d) isalpha()
List- indexing, slicing, methods, functions
Q1: What will be the output of the following code?
python
CopyEdit
lst = [10, 20, 30, 40]
print(lst[1])
a) 10
b) 20 ✅
c) 30
d) 40
Q2: What will lst[-2] return for lst = [5, 10, 15, 20, 25]?
a) 10
b) 15
c) 20 ✅
d) 25
Q3: What does lst[1:4] return for lst = [1, 2, 3, 4, 5]?
a) [1, 2, 3, 4]
b) [2, 3, 4] ✅
c) [2, 3, 4, 5]
d) [1, 3, 4]
Q4: Which method is used to add an element to the end of a list?
a) insert()
b) append() ✅
c) extend()
d) push()
Q5: What does [Link]() do?
a) Removes and returns the first element
b) Removes and returns the last element ✅
c) Deletes the entire list
d) Removes a specific element
Q6: What will be the output of len([1, 2, 3, 4])?
a) 3
b) 4 ✅
c) 5
d) Error
Q7: What will be the result of the following code?
python
CopyEdit
lst = [1, 2, 3]
[Link]([4, 5])
print(lst)
a) [1, 2, 3, [4, 5]]
b) [1, 2, 3, 4, 5] ✅
c) [1, 2, 3, 4]
d) [1, 2, 3, (4, 5)]
Q8: How do you remove an element by its value from a list?
a) [Link](value) ✅
b) [Link](value)
c) del lst[value]
d) [Link](value)
Q9: What will lst * 2 return for lst = [1, 2, 3]?
a) [1, 2, 3] * 2
b) [1, 2, 3, 1, 2, 3] ✅
c) [2, 4, 6]
d) Error
Q10: What will be the output of sorted([3, 1, 4, 2])?
a) [3, 1, 4, 2]
b) [1, 2, 3, 4] ✅
c) [4, 3, 2, 1]
d) None
Tuple- indexing, slicing, methods, functions
Q1: What will be the output of the following code?
python
CopyEdit
tup = (10, 20, 30, 40)
print(tup[2])
a) 10
b) 20
c) 30 ✅
d) 40
Q2: What will tup[-1] return for tup = (5, 10, 15, 20, 25)?
a) 5
b) 10
c) 20
d) 25 ✅
Q3: What does tup[1:4] return for tup = (1, 2, 3, 4, 5)?
a) (1, 2, 3, 4)
b) (2, 3, 4) ✅
c) (2, 3, 4, 5)
d) (1, 3, 4)
Q4: Which of the following statements about tuples is True?
a) Tuples are mutable
b) Tuples cannot store duplicate values
c) Tuples are immutable ✅
d) Tuples use {} instead of ()
Q5: What happens if you try to modify a tuple element like this?
python
CopyEdit
tup = (1, 2, 3)
tup[1] = 5
a) The tuple gets updated
b) No error, but the value remains unchanged
c) It raises a TypeError ✅
d) The program crashes
Q6: What will be the output of len((1, 2, 3, 4))?
a) 3
b) 4 ✅
c) 5
d) Error
Q7: Which of the following methods can be used with a tuple?
a) append()
b) insert()
c) count() ✅
d) remove()
Q8: What will tup * 2 return for tup = (1, 2, 3)?
a) (1, 2, 3, 1, 2, 3) ✅
b) (2, 4, 6)
c) (1, 2, 3) * 2
d) Error
Q9: How do you convert a tuple into a list?
a) list(tup) ✅
b) convert(tup)
c) tup.to_list()
d) [Link]()
Q10: What will be the output of the following code?
python
CopyEdit
tup = (1, 2, 3, 2, 2, 4)
print([Link](2))
a) 1
b) 2
c) 3 ✅
d) 4
Dictionary- keys, value, methods, functions
1. Dictionary Keys, Values, Methods, and Functions MCQs
Q1: What will be the output of the following code?
python
CopyEdit
d = {"a": 1, "b": 2, "c": 3}
print(d["b"])
a) 1
b) 2 ✅
c) 3
d) Error
Q2: What will happen if you try to access a key that does not exist in
a dictionary using dict[key]?
a) Returns None
b) Raises a KeyError ✅
c) Returns an empty string
d) Returns False
Q3: How can you safely access a dictionary key without causing an
error if the key is missing?
a) dict[key]
b) [Link](key) ✅
c) [Link](key)
d) [Link](key)
Q4: Which method returns all the keys in a dictionary?
a) keys() ✅
b) values()
c) items()
d) get_keys()
Q5: What does [Link]() return?
a) A list of dictionary keys
b) A list of dictionary values
c) A list of tuples containing key-value pairs ✅
d) A sorted list of dictionary keys
Q6: What will be the output of the following code?
python
CopyEdit
d = {"x": 10, "y": 20}
d["z"] = 30
print(d)
a) {"x": 10, "y": 20}
b) {"x": 10, "y": 20, "z": 30} ✅
c) {"x": 10, "z": 30}
d) Error
Q7: What does [Link](key) do?
a) Removes a key-value pair and returns the value ✅
b) Removes a key-value pair and returns the key
c) Removes the first key-value pair
d) Clears the entire dictionary
Q8: Which method is used to get all the values in a dictionary?
a) keys()
b) values() ✅
c) items()
d) get_values()
Q9: What will happen if you execute the following code?
python
CopyEdit
d = {"a": 1, "b": 2}
[Link]()
print(d)
a) {"a": 1, "b": 2}
b) None
c) {} ✅
d) Error
Q10: What is the output of the following code?
python
CopyEdit
d = {"x": 5, "y": 10}
print("x" in d)
a) True ✅
b) False
c) None
d) Error
Module: random, collections(counter, OrderedDict,
defaultdict)
Q1: Which function from the random module returns a random integer
between two given numbers inclusive?
a) random()
b) randrange()
c) randint() ✅
d) choice()
Q2: What will be the output of the following code?
python
CopyEdit
import random
print([Link]())
a) A random integer
b) A random float between 0 and 1 ✅
c) A random float between 1 and 10
d) A syntax error
Q3: Which function randomly selects an element from a given list?
a) shuffle()
b) sample()
c) choice() ✅
d) randint()
Q4: What will [Link]() do?
a) Return a sorted list
b) Randomly rearrange elements of the list ✅
c) Pick a random element from the list
d) Remove an element randomly
Q5: What does the [Link](population, k) function do?
a) Selects k unique random elements from the population ✅
b) Returns a single random element
c) Repeats elements in the selection
d) Sorts the elements
Q6: What does the Counter class in the collections module do?
a) Counts the number of elements in a list ✅
b) Sorts the list
c) Removes duplicate elements
d) Returns the most frequent element
Q7: What will be the output of the following code?
python
CopyEdit
from collections import Counter
c = Counter("banana")
print(c)
a) Counter({'b': 1, 'a': 3, 'n': 2}) ✅
b) Counter({'a': 3, 'n': 2, 'b': 1})
c) {b: 1, a: 3, n: 2}
d) Error
Q8: How does an OrderedDict differ from a normal dictionary in Python?
a) It does not allow duplicate keys
b) It remembers the order of insertion ✅
c) It is faster than a normal dictionary
d) It stores only unique values
Q9: What is the purpose of a defaultdict in Python?
a) It returns a default value for missing keys ✅
b) It sorts dictionary keys
c) It ensures all keys have unique values
d) It removes duplicate keys
Q10: What will be the output of the following code?
python
CopyEdit
from collections import defaultdict
d = defaultdict(int)
print(d["missing"])
a) 0 ✅
b) None
c) KeyError
d) Error