Python MCQs
Which of the following is the correct extension of a Python file?
a) .pyth
b) .pt
c) .py ✅
d) .pWhat is the output of
print(2 ** 3 ** 2)?
a) 64
b) 512 ✅
c) 256
d) 8Python is a ___ language.
a) Compiled
b) Interpreted ✅
c) Machine
d) AssemblyWhich of the following is immutable in Python?
a) List
b) Dictionary
c) Tuple ✅
d) SetWhat does
len("Python")return?
a) 5
b) 6 ✅
c) 7
d) ErrorWhat will be the output of:
print(type([]) is list)
a) True ✅
b) False
c) list
d) None
What is the output of
bool("")?
a) True
b) False ✅
c) Error
d) NoneWhich operator is used for floor division?
a) /
b) // ✅
c) %
d) **What is the data type of
True?
a) int
b) bool ✅
c) str
d) NoneTypeWhich of the following statements will create a dictionary?
a)d = {}✅
b)d = []
c)d = ()
d)d = set()What does
print(3 * 'ab')output?
a) ababab ✅
b) 9
c) Error
d) ‘ab3’How do you start an if statement in Python?
a)if x > 0 then:
b)if x > 0:✅
c)if (x > 0)
d)if x > 0 beginWhich of these is not a valid keyword?
a) pass
b) eval ✅
c) assert
d) finallyWhich method adds an element to a list?
a) insert()
b) add()
c) append() ✅
d) push()What is the output of:
x = [1, 2, 3]
x.insert(0, 0)
print(x)
a) [0,1,2,3] ✅
b) [1,2,3,0]
c) [1,0,2,3]
d) [0,1,3,2]
16. What will type({}) return?
a) list
b) set
c) dict ✅
d) tuple
What is the output of:
x = 5
y = 2
print(x / y)
a) 2.5 ✅
b) 2
c) 2.0
d) 2.25
18. What is the output of:
print('hello' == "hello")
a) True ✅
b) False
c) Error
d) None
19. Which function is used to find the largest number?
a) max() ✅
b) largest()
c) top()
d) big()
What is the output of
print(type( (1,) ))?
a) tuple ✅
b) list
c) int
d) dictWhich keyword is used to define a function?
a) func
b) def ✅
c) define
d) functionWhich statement is used to exit a loop early?
a) exit
b) stop
c) break ✅
d) returnHow can you comment multiple lines in Python?
a) /* comment */
b) # comment
c) “”” comment “”” ✅
d) // commentWhat does the
continuestatement do?
a) Ends loop
b) Skips iteration ✅
c) Repeats loop
d) Exits functionWhat is the output of
print(2 in [1,2,3])?
a) True ✅
b) False
c) None
d) ErrorWhich of the following is used to import a module?
a) load
b) include
c) import ✅
d) requireHow do you import only sqrt from math module?
a) import math.sqrt
b) from math import sqrt ✅
c) import sqrt
d) using math.sqrtWhich function converts a string to lowercase?
a) lower() ✅
b) down()
c) low()
d) min()What is the output of
print(bool([]))?
a) True
b) False ✅
c) None
d) ErrorWhat is the output of:
x = [1,2,3]
print(x[1:])
a) [2,3] ✅
b) [1,2]
c) [1,2,3]
d) [3]
31. Which operator checks for identity?
a) ==
b) is ✅
c) equals
d) :=
What is the output of
"abc" * 2?
a) abcabc ✅
b) aabbcc
c) abc2
d) ErrorWhich of the following is NOT a Python data type?
a) int
b) float
c) real ✅
d) dictWhat is the result of:
a = [1,2,3]
b = a
b.append(4)
print(a)
a) [1,2,3,4] ✅
b) [1,2,3]
c) [4]
d) Error
35. What is the default return value of a function that doesn’t use return?
a) 0
b) False
c) None ✅
d) Empty string
What will
range(3)produce?
a) [1,2,3]
b) [0,1,2] ✅
c) (1,2,3)
d) ErrorWhat is the output of
print(3 > 2 > 1)?
a) True ✅
b) False
c) Error
d) NoneWhich built-in function is used to get user input?
a) scan()
b) get()
c) input() ✅
d) enter()Which method is used to remove whitespace from both ends of a string?
a) trim()
b) strip() ✅
c) split()
d) remove()Which keyword is used for exceptions?
a) throw
b) raise ✅
c) except
d) tryWhat is the output of
print(type(range(5)))?
a) list
b) range ✅
c) tuple
d) intWhat is the result of:
x = {1,2,3,2}
print(len(x))
a) 4
b) 3 ✅
c) 2
d) Error
43. What is the output of:
"Hello World".split()
a) ['Hello', 'World'] ✅
b) ['Hello World']
c) ('Hello','World')
d) Error
44. Which function converts a list into a tuple?
a) list()
b) tuple() ✅
c) convert()
d) set()
Which statement defines a class?
a) def ClassName:
b) class ClassName: ✅
c) define ClassName:
d) create ClassName:Which method returns all keys in a dictionary?
a) getkeys()
b) allkeys()
c) keys() ✅
d) list()What is the output of:
x = "python"
print(x[2:5])
a) tho
b) yth
c) tho ✅
d) pyt
48. What is the output of print(bool(0))?
a) True
b) False ✅
c) 0
d) None
Which of these will raise an error?
a) 1 + 2
b) “2” + 3 ✅
c) 3 * 2
d) “a” + “b”What does
dict.get(key)return if the key doesn’t exist?
a) Error
b) None ✅
c) False
d) Empty string
What is the output of:
print(list(range(2,10,2)))
a) [2,4,6,8] ✅
b) [2,4,6,8,10]
c) [2,3,4,5,6,7,8,9]
d) Error
Which of these is not a valid string method?
a) upper()
b) replace()
c) reverse() ✅
d) join()How do you create an empty set?
a) s = {}
b) s = set() ✅
c) s = []
d) s = ()What is the output of:
print(type( (1) ))
a) int ✅
b) tuple
c) list
d) None
Which method adds multiple elements to a list?
a) add()
b) extend() ✅
c) append()
d) insert()What does
__init__()do in Python?
a) It’s a destructor
b) It initializes a class ✅
c) It deletes a class
d) It returns an iteratorWhat is the output of:
x = [1,2,3]
print(x.pop())
a) 1
b) 2
c) 3 ✅
d) Error
How do you define a lambda function?
a)def x():
b)lambda x:✅
c)func x():
d)define x:What is the output of:
print(bool("False"))
a) False
b) True ✅
c) Error
d) None
Which of the following is NOT a Python loop?
a) for
b) while
c) loop ✅
d) nestedWhat does
ord('A')return?
a) 65 ✅
b) 66
c) 64
d) ErrorWhat does
chr(65)return?
a) A ✅
b) 65
c) a
d) ErrorWhich keyword is used to inherit a class?
a) import
b) extends
c) class Child(Parent): ✅
d) inheritWhat is the output of:
x = [1,2,3]
print(sum(x))
a) 6 ✅
b) 5
c) Error
d) 3
What will
print(10//3)output?
a) 3 ✅
b) 3.3
c) 4
d) 2Which of these functions converts a value to string?
a) str() ✅
b) string()
c) toString()
d) chr()How can you get both index and value while looping through a list?
a) enumerate() ✅
b) index()
c) list()
d) zip()What is the output of
print(3 * [0])?
a) [0,0,0] ✅
b) 000
c) [3,3,3]
d) ErrorWhat is the default mode of
open()function?
a) read ✅
b) write
c) append
d) binaryWhich method is used to read a single line from a file?
a) readline() ✅
b) read()
c) readlines()
d) readall()What will be the output of:
x = "Python"
print(x[::-1])
a) nohtyP ✅
b) Python
c) Error
d) pYTHON
What is the output of:
x = [1,2,3,4]
print(x[-1])
a) 4 ✅
b) 3
c) Error
d) None
Which of these statements will raise an error?
a) eval(‘2+3’)
b) int(‘xyz’) ✅
c) int(’10’)
d) float(‘3.14’)What is the output of:
print(all([True, False, True]))
a) True
b) False ✅
c) None
d) Error
What is the output of
any([0, "", None, 5])?
a) True ✅
b) False
c) Error
d) NoneWhat is the output of:
print([i for i in range(5) if i%2==0])
a) [0,2,4] ✅
b) [1,3,5]
c) [2,4]
d) Error
Which of these is a mutable type?
a) Tuple
b) List ✅
c) String
d) FrozensetWhat is the output of:
print(10 != 5)
a) True ✅
b) False
c) Error
d) None
Which function returns the number of items in an object?
a) count()
b) len() ✅
c) sum()
d) size()What is the output of
print(divmod(10,3))?
a) (3,1) ✅
b) (3,0)
c) (10,3)
d) ErrorWhich function is used to get the memory location of an object?
a) address()
b) location()
c) id() ✅
d) get()What is the output of:
x = [1,2,3]
print(x*2)
a) [1,2,3,1,2,3] ✅
b) [2,4,6]
c) [1,2,3]
d) Error
Which of the following is used to define anonymous functions?
a) lambda ✅
b) def
c) anon
d) funcWhat is the output of:
x = {1,2,3}
x.add(4)
print(x)
a) {1,2,3,4} ✅
b) [1,2,3,4]
c) Error
d) {4}
What is the output of
min([2,5,1,9])?
a) 9
b) 2
c) 1 ✅
d) 5What is the output of
max('abc')?
a) a
b) b
c) c ✅
d) ErrorWhat is the result of
" ".join(['Python','MCQ'])?
a) [‘Python’,’MCQ’]
b) PythonMCQ
c) Python MCQ ✅
d) ErrorWhich keyword is used to skip a block of code without error?
a) break
b) continue
c) pass ✅
d) skipWhat is the output of
print(type(lambda x: x))?
a) function ✅
b) lambda
c) object
d) methodWhat is the output of
print(5 and 0)?
a) 5
b) 0 ✅
c) True
d) FalseWhich of the following can’t be used as a variable name?
a) myVar
b) _x
c) True ✅
d) data1What is the output of
print(list("abc"))?
a) [‘abc’]
b) [‘a’,’b’,’c’] ✅
c) (a,b,c)
d) ErrorWhich of the following is used to convert a string into a list of words?
a) split() ✅
b) break()
c) divide()
d) cut()What is the output of:
x = [1,2,3]
y = x.copy()
y.append(4)
print(x)
a) [1,2,3,4]
b) [1,2,3] ✅
c) [4]
d) Error
Which function gives the type of a variable?
a) typeof()
b) type() ✅
c) gettype()
d) vartype()What is the output of:
print(list(range(5,1,-1)))
a) [5,4,3,2] ✅
b) [1,2,3,4,5]
c) [5,4,3,2,1]
d) Error
What is the output of
abs(-7)?
a) -7
b) 7 ✅
c) 0
d) ErrorWhat is the output of
round(5.678, 2)?
a) 5.67
b) 5.68 ✅
c) 5.6
d) 5.7Which of these is a Python built-in module?
a) os ✅
b) pandas
c) requests
d) flaskWhat is the output of
print(5 is 5)?
a) True ✅
b) False
c) Error
d) None
What is the output of:
x = [1,2,3]
print(x[::-1])
a) [3,2,1] ✅
b) [1,2,3]
c) [1,3,2]
d) Error
What is the output of
"Python".find('y')?
a) 0
b) 1 ✅
c) 2
d) -1Which of these functions removes duplicates from a list?
a) list(set(l)) ✅
b) remove()
c) unique()
d) dedup()What is the output of
print(9 // 2)?
a) 4.5
b) 4 ✅
c) 5
d) 5.0Which function returns the ASCII value of a character?
a) ord() ✅
b) chr()
c) ascii()
d) ordval()What is the output of:
x = (1,2,3)
x[0] = 10
a) (10,2,3)
b) Error ✅
c) None
d) [10,2,3]
What is the output of
"PYTHON".lower()?
a) python ✅
b) PYTHON
c) Python
d) ErrorWhich of the following is false about Python dictionaries?
a) Keys must be unique ✅
b) Values can be duplicated
c) Keys must be immutable
d) Keys can be listsWhat does
zip()do in Python?
a) Compress data
b) Combine iterables ✅
c) Sort elements
d) NoneWhich of the following is used to read all lines from a file?
a) read()
b) readline()
c) readlines() ✅
d) scanlines()What is the output of:
print(bool(None))
a) True
b) False ✅
c) None
d) Error
What is the output of:
print(4**(1/2))
a) 2 ✅
b) 4
c) 8
d) 16
Which function is used to sort a list permanently?
a) sort() ✅
b) sorted()
c) order()
d) arrange()What is the output of
sorted([3,1,2])?
a) [1,2,3] ✅
b) [3,2,1]
c) [3,1,2]
d) ErrorWhat is the output of:
print(type(True + False))
a) bool
b) int ✅
c) str
d) Error
Which method is used to remove an item by value from a list?
a) delete()
b) remove() ✅
c) pop()
d) discard()What will
print(10 % 3)output?
a) 1 ✅
b) 3
c) 0
d) ErrorWhat does
x, y = y, xdo in Python?
a) Swaps x and y ✅
b) Compares x and y
c) Duplicates x
d) NoneWhat is the output of
"abc".upper()?
a) abc
b) ABC ✅
c) Abc
d) ErrorWhat is the output of
"abc".capitalize()?
a) abc
b) Abc ✅
c) ABC
d) aBCWhat does
list('123')return?
a) [1,2,3]
b) [‘1′,’2′,’3’] ✅
c) [‘123’]
d) ErrorWhich of these is a valid set declaration?
a) s = set([1,2,3]) ✅
b) s = {1:2, 3:4}
c) s = [1,2,3]
d) s = (1,2,3)What is the output of:
x = [1,2,3]
print(len(x))
a) 3 ✅
b) 2
c) 4
d) Error
What does
help(len)do?
a) Prints documentation ✅
b) Runs len()
c) Counts help
d) ErrorWhat is the output of:
print(type( (1,2,3) ))
a) tuple ✅
b) list
c) set
d) dict
What is the output of
print(2 ** 4)?
a) 8
b) 16 ✅
c) 4
d) 32What is the output of:
print("a" in "apple")
a) True ✅
b) False
c) Error
d) None
Which function returns the absolute value of a number?
a) fabs()
b) abs() ✅
c) absolute()
d) val()What is the output of:
x = {"a":1, "b":2}
print("a" in x)
a) True ✅
b) False
c) Error
d) None
What is the output of:
for i in range(2):
print(i)
else:
print("done")
a) 0 1 done ✅
b) 0 1
c) done
d) Error
Which of these keywords defines an empty block?
a) continue
b) break
c) pass ✅
d) returnWhat is the output of
"Python"[1:4]?
a) Pyt
b) yth ✅
c) ytho
d) hytWhat is the output of
print(len(set("banana")))?
a) 6
b) 3 ✅
c) 4
d) 2Which method returns the number of occurrences of a substring?
a) count() ✅
b) find()
c) index()
d) occurrences()What is the output of:
x = [1,2,3]
y = x
y.append(4)
print(x)
a) [1,2,3,4] ✅
b) [1,2,3]
c) [4]
d) None
Which function converts string to integer safely?
a) str()
b) eval()
c) int() ✅
d) input()What is the output of:
print(5 > 3 and 2 < 1)
a) True
b) False ✅
c) Error
d) None
What will
print(type([]) == list)return?
a) True ✅
b) False
c) None
d) ErrorWhat is the output of
print(not 0)?
a) True ✅
b) False
c) None
d) 0What is the output of:
print(bool(" "))
a) False
b) True ✅
c) None
d) Error
What will
len({1: "a", 2: "b"})return?
a) 1
b) 2 ✅
c) 0
d) 3Which keyword is used to define a generator?
a) yield ✅
b) gen
c) lambda
d) nextWhat is the output of:
for i in range(3):
if i == 1: break
else:
print("done")
a) done
b) Nothing ✅
c) Error
d) 0 1 done
What is the output of
print(sum([1,2,3,4]))?
a) 9
b) 10 ✅
c) 8
d) ErrorWhat is the output of
print(3*'ab')?
a) ababab ✅
b) abab
c) 3ab
d) ErrorWhich of these is false about tuples?
a) They are immutable ✅
b) They can store duplicate elements
c) They can contain different types
d) They support slicingWhat will
print(5 == 5.0)output?
a) True ✅
b) False
c) None
d) ErrorWhat is the output of
list(range(0))?
a) [] ✅
b) [0]
c) [1]
d) ErrorWhat is the output of
print("abc" + "def")?
a) abcdef ✅
b) abc def
c) abc+def
d) ErrorWhich built-in function can execute a string as code?
a) exec() ✅
b) run()
c) evalstr()
d) compile()
Which of the following can be used to import a module with a different name?
a) import math as m ✅
b) import math from m
c) rename math to m
d) use math as mWhat is the output of:
print(pow(2,3))
a) 6
b) 8 ✅
c) 9
d) Error
What is the output of:
print(type({1,2,3}))
a) list
b) set ✅
c) dict
d) tuple
Which statement will raise an exception?
a) int(‘123’)
b) int(‘abc’) ✅
c) float(‘2.5’)
d) str(25)What is the output of:
x = [1,2,3]
print(x*0)
a) [] ✅
b) [0,0,0]
c) [1,2,3]
d) Error
What will
print("Hello {}".format("World"))output?
a) Hello World ✅
b) Hello {}
c) Hello ‘World’
d) ErrorWhat does
locals()return?
a) Dictionary of local variables ✅
b) List of global variables
c) Memory address
d) NoneWhat does
globals()return?
a) Global namespace ✅
b) Local namespace
c) Modules
d) Environment variablesWhat is the output of:
print(10 > 5 or 2 > 3)
a) True ✅
b) False
c) Error
d) None
Which of the following creates a tuple with one element?
a) (1,) ✅
b) (1)
c) [1,]
d) {1,}What is the output of:
print('a' * 3)
a) a
b) aaa ✅
c) 3a
d) Error
Which statement is true about Python lists?
a) They are immutable
b) They are ordered ✅
c) They are sets
d) They can’t contain duplicatesWhat is the output of:
print(isinstance(5, int))
a) True ✅
b) False
c) None
d) Error
Which module is used for random number generation?
a) random ✅
b) math
c) os
d) sysWhat is the output of:
import random
print(type(random.random()))
a) int
b) float ✅
c) str
d) NoneType
What is the output of:
print("abc".replace("a","z"))
a) zbc ✅
b) abc
c) azc
d) zcc
Which function finds the minimum value from arguments?
a) min() ✅
b) smallest()
c) least()
d) low()Which of the following statements is invalid?
a) x = 10
b) 10 = x ✅
c) x, y = 1, 2
d) x += 5What does
dir()function do?
a) Lists all attributes/methods ✅
b) Lists directories
c) Returns documentation
d) Deletes variablesWhat is the output of:
print(type(10.0))
a) int
b) float ✅
c) decimal
d) number
Which keyword is used to define a class?
a) def
b) class ✅
c) define
d) objectWhat is the output of:
x = {1:'a', 2:'b'}
print(x[2])
a) 1
b) a
c) b ✅
d) Error
What is the output of:
print(bool([]) == False)
a) True ✅
b) False
c) None
d) Error
What is the result of:
print(3 in [1,2,3,4])
a) True ✅
b) False
c) Error
d) None
What is the output of:
x = [1,2,3]
print(x[-2])
a) 2 ✅
b) 3
c) 1
d) Error
What is the output of:
print(3 * (1 + 2))
a) 9 ✅
b) 6
c) 5
d) 3
What is the output of
"hello".title()?
a) Hello ✅
b) HELLO
c) hello
d) hELLOWhich built-in function returns the largest integer ≤ x?
a) ceil()
b) floor() ✅
c) round()
d) trunc()Which module contains floor()?
a) random
b) math ✅
c) sys
d) timeWhat does
isinstance("abc", str)return?
a) True ✅
b) False
c) None
d) ErrorWhich statement is correct about Python indentation?
a) It’s optional
b) It defines blocks ✅
c) It’s ignored
d) It must use tabs onlyWhat is the output of:
print(5 | 3)
a) 1
b) 7 ✅
c) 15
d) 8
What is the output of:
print(5 & 3)
a) 7
b) 1 ✅
c) 0
d) 8
Which bitwise operator inverts bits?
a) ~ ✅
b) ^
c) |
d) &What is the output of:
print(~2)
a) -3 ✅
b) -2
c) 3
d) 2
What is the output of:
print(2 << 1)
a) 4 ✅
b) 1
c) 2
d) 8
What is the output of:
print(8 >> 2)
a) 2 ✅
b) 4
c) 8
d) 1
Which function is used to get the current working directory?
a) os.getcwd() ✅
b) sys.getcwd()
c) os.current()
d) os.path()What is the output of:
x = "Python"
print(len(x))
a) 5
b) 6 ✅
c) 7
d) Error
Which function is used to remove a key from a dictionary?
a) pop() ✅
b) remove()
c) delete()
d) discard()What is the output of
"abc".isalpha()?
a) True ✅
b) False
c) Error
d) NoneWhat is the output of
"123".isdigit()?
a) True ✅
b) False
c) Error
d) NoneWhich function can reverse a list?
a) reverse() ✅
b) flip()
c) turn()
d) rev()What is the output of
list(reversed([1,2,3]))?
a) [3,2,1] ✅
b) [1,2,3]
c) Error
d) NoneWhich function returns both index and element in a loop?
a) enumerate() ✅
b) index()
c) items()
d) zip()What is the output of:
x = {'a':1, 'b':2}
print(x.items())
a) [(‘a’,1), (‘b’,2)] ✅
b) [‘a’,’b’]
c) {1,2}
d) Error
Which function checks if all elements are True?
a) all() ✅
b) any()
c) bool()
d) check()What is the output of
any([0, 1, 0])?
a) True ✅
b) False
c) None
d) ErrorWhich of the following is a correct lambda syntax?
a) lambda x: x+2 ✅
b) def x -> x+2
c) func(x) = x+2
d) define x: x+2What is the output of:
print(type( (i for i in range(3)) ))
a) list
b) tuple
c) generator ✅
d) range
201. What is the output of:
print(list(map(lambda x: x**2, [1,2,3])))
a) [1,2,3]
b) [1,4,9] ✅
c) [2,3,4]
d) Error
What is the output of:
x = [1,2,3]
y = [4,5]
print(x + y)
a) [1,2,3,4,5] ✅
b) [5,7,8]
c) (1,2,3,4,5)
d) Error
Which of the following creates a set comprehension?
a) {x for x in range(5)} ✅
b) [x for x in range(5)]
c) (x for x in range(5))
d) set(x in range(5))What is the output of
print(sum([True, False, True]))?
a) 1
b) 2 ✅
c) 3
d) 0What is the output of:
print([i for i in range(5) if i%2==0])
a) [1,3,5]
b) [0,2,4] ✅
c) [2,4,6]
d) [0,1,2,3,4]
Which function returns the maximum of iterable values?
a) max() ✅
b) large()
c) greatest()
d) big()What is the output of:
x = [1,2,3]
x.insert(1,10)
print(x)
a) [10,1,2,3]
b) [1,10,2,3] ✅
c) [1,2,10,3]
d) Error
What is the output of
divmod(9,2)?
a) (4,1) ✅
b) (4,2)
c) (4.5,0)
d) ErrorWhich function checks if an object is callable?
a) callable() ✅
b) call()
c) iscall()
d) func()What is the output of:
x = lambda a,b: a*b
print(x(2,3))
a) 6 ✅
b) 5
c) Error
d) 23
What is the output of:
print(list(range(2,10,3)))
a) [2,3,4,5,6,7,8,9]
b) [2,5,8] ✅
c) [3,6,9]
d) Error
What is the output of
"python".startswith("py")?
a) True ✅
b) False
c) None
d) ErrorWhat does
enumerate(["a","b","c"])return?
a) [(0,”a”),(1,”b”),(2,”c”)] ✅
b) [0,”a”,”b”,”c”]
c) (0,”a”,”b”,”c”)
d) NoneWhich function returns a new list sorted without modifying the original?
a) sorted() ✅
b) sort()
c) arrange()
d) order()What is the output of:
print(bool('False'))
a) True ✅
b) False
c) Error
d) None
What is the output of:
print([x for x in range(5) if x])
a) [0,1,2,3,4]
b) [1,2,3,4] ✅
c) [0,1,2,3]
d) Error
Which of these methods belongs to a string object?
a) split() ✅
b) push()
c) add()
d) extend()What is the output of
"Python".index("t")?
a) 2 ✅
b) 3
c) 1
d) ErrorWhat will
"Python".count("P")return?
a) 0
b) 1 ✅
c) 2
d) ErrorWhich function gives the absolute difference between two sets?
a) symmetric_difference() ✅
b) difference()
c) union()
d) intersection()What is the output of:
set1 = {1,2,3}
set2 = {3,4}
print(set1 & set2)
a) {1,2,3,4}
b) {3} ✅
c) {1,2}
d) {}
What is the output of:
print({1,2,3}.issubset({1,2,3,4}))
a) True ✅
b) False
c) None
d) Error
What is the output of
"abc" * 0?
a) ” ✅
b) abc
c) 0
d) ErrorWhich method adds multiple items to a list?
a) append()
b) extend() ✅
c) insert()
d) add()Which of these is used to catch exceptions?
a) try…except ✅
b) catch()
c) handle()
d) stop()What is the output of:
try:
print(1/0)
except ZeroDivisionError:
print("error")
a) 1/0
b) error ✅
c) ZeroDivisionError
d) None
What is the output of:
try:
pass
finally:
print("done")
a) done ✅
b) Error
c) None
d) pass
What is the output of
type(5j)?
a) complex ✅
b) float
c) int
d) imaginaryWhich operator is used for identity comparison?
a) is ✅
b) ==
c) ===
d) eqWhat is the output of:
x = [1,2]
y = [1,2]
print(x is y)
a) True
b) False ✅
c) None
d) Error
What is the output of
type(range(5))?
a) list
b) range ✅
c) generator
d) iteratorWhat is the output of:
print(" ".join(["a","b","c"]))
a) “a b c” ✅
b) “abc”
c) “a,b,c”
d) Error
What will
"PYTHON".isupper()return?
a) True ✅
b) False
c) Error
d) NoneWhat will
"py".islower()return?
a) True ✅
b) False
c) None
d) ErrorWhich method removes whitespace from both ends of a string?
a) strip() ✅
b) trim()
c) remove()
d) cut()What is the output of
"abc".replace("a","")?
a) “bc” ✅
b) “a”
c) “abc”
d) “”What is the output of:
print(len(" "))
a) 0
b) 1 ✅
c) 2
d) Error
What is the output of:
print(bool([] and [1]))
a) True
b) False ✅
c) []
d) Error
What is the output of:
print(bool([] or [1]))
a) []
b) [1] ✅
c) True
d) False
Which operator checks membership?
a) in ✅
b) is
c) ==
d) hasWhich module handles JSON in Python?
a) json ✅
b) os
c) pickle
d) textWhat is the output of:
import json
print(type(json.dumps({"a":1})))
a) str ✅
b) dict
c) bytes
d) None
Which function converts JSON string to Python object?
a) json.loads() ✅
b) json.dumps()
c) json.read()
d) json.convert()Which function converts Python object to JSON string?
a) json.dumps() ✅
b) json.loads()
c) json.write()
d) json.jsonify()What is the output of:
a = [1,2,3]
b = a.copy()
print(a is b)
a) True
b) False ✅
c) None
d) Error
Which of these creates an empty dictionary?
a) {} ✅
b) []
c) set()
d) dict[]Which statement is used to exit a loop?
a) break ✅
b) exit
c) pass
d) stopWhich function returns a sorted list of dictionary keys?
a) sorted(dict.keys()) ✅
b) sort(dict.keys())
c) dict.sort()
d) order(dict)What is the output of:
x = [1,2,3]
del x[1]
print(x)
a) [1,3] ✅
b) [2,3]
c) [1,2]
d) Error
What is the output of:
print(all([]))
a) True ✅
b) False
c) None
d) Error
251. What is the output of:
print(type(lambda x: x))
a) function ✅
b) lambda
c) object
d) method
Which keyword is used to inherit a class?
a) class Child(Base): ✅
b) inherit Base
c) Base -> Child
d) extends BaseWhat is the output of:
class A:
def __init__(self):
self.x = 10
a = A()
print(hasattr(a, 'x'))
a) True ✅
b) False
c) None
d) Error
What will
getattr(a, 'x', 0)return if attributexdoesn’t exist?
a) 0 ✅
b) None
c) Error
d) FalseWhich method is called when an object is created?
a) new()
b) init() ✅
c) start()
d) create()Which method returns a string representation of an object?
a) repr() ✅
b) str()
c) name()
d) display()What is the output of:
print(bool(0.000))
a) False ✅
b) True
c) 0.000
d) Error
What is the output of:
print({i:i**2 for i in range(3)})
a) {0:0,1:1,2:4} ✅
b) {1:1,2:2,3:3}
c) [0,1,4]
d) Error
What is
__name__when a Python script is run directly?
a) “main” ✅
b) script
c) function
d) NoneWhat is the output of
isinstance(True, int)?
a) True ✅
b) False
c) Error
d) NoneWhich of the following functions imports a module dynamically?
a) import() ✅
b) importlib()
c) execimport()
d) import()Which exception is raised for invalid index access?
a) IndexError ✅
b) KeyError
c) ValueError
d) NameErrorWhich exception occurs when converting a non-numeric string to int?
a) ValueError ✅
b) TypeError
c) SyntaxError
d) NameErrorWhat is the output of:
try:
x = 1/0
except Exception as e:
print(type(e).__name__)
a) ZeroDivisionError ✅
b) Exception
c) Error
d) None
Which function checks memory location of an object?
a) id() ✅
b) loc()
c) address()
d) ref()What is the output of:
x = [1,2,3]
print(x.pop())
a) 3 ✅
b) 2
c) [1,2]
d) Error
What does the
withstatement do?
a) Manages context (auto close resources) ✅
b) Declares function
c) Imports module
d) Creates loopWhat is the output of:
with open("temp.txt","w") as f:
f.write("Hi")
print(f.closed)
a) True ✅
b) False
c) None
d) Error
What is the output of:
import math
print(math.ceil(4.2))
a) 4
b) 5 ✅
c) 4.2
d) 6
Which module is used to work with dates and times?
a) datetime ✅
b) time
c) calendar
d) osWhat does
datetime.date.today()return?
a) Current date ✅
b) Current time
c) Timestamp
d) StringWhich function pauses program execution?
a) time.sleep() ✅
b) wait()
c) pause()
d) stop()Which module provides command-line arguments?
a) sys ✅
b) os
c) argparse
d) getoptWhat is the output of:
import sys
print(sys.version_info.major)
a) Python major version ✅
b) sys info
c) 3.x.x
d) Error
Which function removes and returns last element of a list?
a) pop() ✅
b) del()
c) remove()
d) drop()Which function creates an iterator from multiple iterables?
a) zip() ✅
b) join()
c) map()
d) list()What is the output of:
list(zip([1,2],[3,4,5]))
a) [(1,3),(2,4)] ✅
b) [(1,3),(2,4),(5,None)]
c) Error
d) [1,2,3,4]
Which function executes code from a file?
a) exec(open(“file.py”).read()) ✅
b) run(“file.py”)
c) import file
d) os.run()What does
input()return?
a) Always a string ✅
b) int if numeric
c) Depends on input
d) NoneWhat is the output of:
print("abc".center(7, "-"))
a) –abc– ✅
b) -abc-
c) abc—-
d) —abc
Which module supports regular expressions?
a) re ✅
b) regex
c) pattern
d) matchWhat is the output of:
import re
print(re.findall(r'\d+', 'a1b22c333'))
a) [‘1′,’22’,’333′] ✅
b) [‘a’,’b’,’c’]
c) [1,22,333]
d) None
What is the output of:
print(",".join(map(str,[1,2,3])))
a) 1,2,3 ✅
b) [1,2,3]
c) 123
d) Error
What is the output of:
print(hex(255))
a) 0xff ✅
b) ff
c) 255
d) 0x255
What is the output of
bin(8)?
a) 0b1000 ✅
b) 1000
c) 8
d) 0b8Which function converts integer to octal string?
a) oct() ✅
b) hex()
c) bin()
d) str()Which of the following opens a file in binary read mode?
a) open(‘f.txt’,’rb’) ✅
b) open(‘f.txt’,’br’)
c) open(‘f.txt’,’r+b’)
d) open(‘f.txt’,’r’)What is the output of:
a = [1,2,3]
print(next(iter(a)))
a) 1 ✅
b) 2
c) 3
d) Error
Which statement correctly defines a generator?
a) yield keyword inside a function ✅
b) def with return
c) lambda function
d) class with iterWhat is the output of:
def gen():
yield 1
yield 2
print(list(gen()))
a) [1,2] ✅
b) [2,1]
c) [1]
d) Error
What does
next()do on an iterator?
a) Returns next item ✅
b) Resets iterator
c) Repeats last
d) Deletes itemWhich module provides system-level operations like file paths?
a) os ✅
b) sys
c) path
d) shutilWhat is the output of:
import os
print(os.path.basename("/user/bin/python"))
a) python ✅
b) bin
c) user
d) /python
What is the output of:
print(round(5.678, 2))
a) 5.68 ✅
b) 5.67
c) 5.6
d) 6.0
Which of these functions shuffles a list randomly?
a) random.shuffle() ✅
b) random.mix()
c) randomize()
d) random.change()What is the output of:
print(all([1,2,0]))
a) True
b) False ✅
c) Error
d) None
Which statement is true for decorators?
a) They modify function behavior ✅
b) They compile code
c) They change return type
d) They execute asynchronouslyWhat is the output of:
def deco(f):
def inner(): return "Decorated"
return inner
@deco
def test(): return "Plain"
print(test())
a) Plain
b) Decorated ✅
c) None
d) Error
Which keyword is used to define an anonymous block that does nothing?
a) pass ✅
b) null
c) continue
d) nopWhat is the output of:
print(sum(i*i for i in range(4)))
a) 14 ✅
b) 10
c) 16
d) 9
301. What is the output of:
print(type([]) is list)
a) True ✅
b) False
c) list
d) None
Which keyword is used to create an inline anonymous function?
a) lambda ✅
b) def
c) anon
d) funcWhat will be the result of:
print('Python'.find('y'))
a) 1 ✅
b) 0
c) 2
d) -1
What is the output of:
print('Hello' * 3)
a) HelloHelloHello ✅
b) Hello3
c) Error
d) None
Which of the following is used to define a block of code in Python?
a) Indentation ✅
b) Braces {}
c) Parentheses ()
d) SemicolonsWhat does
max([3,5,2,8])return?
a) 8 ✅
b) 3
c) 2
d) 5Which of these is a valid variable name?
a) my_var ✅
b) 1var
c) var-1
d) my varWhat will
print(bool('False'))output?
a) True ✅
b) False
c) ‘False’
d) NoneWhat is the output of:
a = [1,2,3]
b = a
b.append(4)
print(a)
a) [1,2,3,4] ✅
b) [1,2,3]
c) Error
d) [4]
What is the type of the object created by
range(5)?
a) range ✅
b) list
c) tuple
d) iteratorWhat will
bool([])return?
a) False ✅
b) True
c) None
d) ErrorWhich function returns the number of elements in an object?
a) len() ✅
b) count()
c) size()
d) total()What is the output of:
print(10 // 3)
a) 3 ✅
b) 3.33
c) 4
d) Error
What is the output of
2 == 2.0?
a) True ✅
b) False
c) Error
d) NoneWhich statement is true about Python lists?
a) Lists are mutable ✅
b) Lists are immutable
c) Lists store only numbers
d) Lists are fixed-lengthWhich of the following is a Python tuple?
a) (1,2,3) ✅
b) [1,2,3]
c) {1,2,3}
d) tuple[1,2,3]What will
print(type({}))output?
a) <class ‘dict’> ✅
b) <class ‘set’>
c) <class ‘list’>
d) NoneWhich method adds an element to a set?
a) add() ✅
b) append()
c) insert()
d) push()What is the output of:
print(bool(None))
a) False ✅
b) True
c) None
d) Error
Which of these is a correct dictionary declaration?
a) {‘a’:1, ‘b’:2} ✅
b) {1,2,3}
c) [‘a’,1]
d) (‘a’:1)What is the output of:
d = {'a':1,'b':2}
print(d.get('c', 0))
a) 0 ✅
b) None
c) Error
d) ‘c’
Which function returns all keys in a dictionary?
a) keys() ✅
b) values()
c) items()
d) get()What will
list("abc")produce?
a) [‘a’,’b’,’c’] ✅
b) [‘abc’]
c) (‘a’,’b’,’c’)
d) ErrorWhat does
enumerate(['a','b'])return?
a) Iterator of (index, value) pairs ✅
b) List of tuples
c) Dictionary
d) NoneWhat is the output of:
print(any([0, False, 3]))
a) True ✅
b) False
c) 3
d) Error
Which of the following removes whitespace from both ends of a string?
a) strip() ✅
b) trim()
c) remove()
d) clean()What is the output of:
print('python'.capitalize())
a) Python ✅
b) python
c) PYTHON
d) None
Which function converts string to lowercase?
a) lower() ✅
b) down()
c) casefold()
d) reduce()What is the output of:
print('PYTHON'.lower())
a) python ✅
b) PYTHON
c) None
d) Error
Which method checks if a string starts with a specific substring?
a) startswith() ✅
b) begins()
c) prefix()
d) check()Which method returns the index of a substring?
a) find() ✅
b) locate()
c) indexof()
d) position()What is the output of:
print('abc'.upper())
a) ABC ✅
b) abc
c) None
d) Error
Which statement defines a function in Python?
a) def func(): ✅
b) function func():
c) define func():
d) func def():What is the output of:
def f(x=5): return x+1
print(f())
a) 6 ✅
b) 5
c) Error
d) None
Which keyword is used to return a value from a function?
a) return ✅
b) yield
c) pass
d) endWhat is the output of:
x = lambda a,b : a+b
print(x(2,3))
a) 5 ✅
b) 6
c) Error
d) 2+3
What is recursion in Python?
a) Function calling itself ✅
b) Nested loops
c) Class inheritance
d) NoneWhat will be printed by:
def test(a,b=2,c=3): print(a,b,c)
test(1)
a) 1 2 3 ✅
b) 1 3 2
c) Error
d) None
Which function returns documentation string of a function?
a) help() ✅
b) doc()
c) info()
d) describe()What is the output of:
print(3 in [1,2,3])
a) True ✅
b) False
c) Error
d) None
What will happen if you divide by zero?
a) ZeroDivisionError ✅
b) ValueError
c) TypeError
d) NoneWhat is the output of:
try:
print(1/1)
except:
print("Error")
else:
print("OK")
a) 1.0 OK ✅
b) Error
c) OK
d) None
What is the output of:
a = [1,2,3]
print(sum(a))
a) 6 ✅
b) 123
c) Error
d) None
Which statement reads an entire file as a string?
a) f.read() ✅
b) f.readline()
c) f.readlines()
d) file.read()Which statement appends data to a file?
a) open(‘file.txt’,’a’) ✅
b) open(‘file.txt’,’r’)
c) open(‘file.txt’,’w’)
d) open(‘file.txt’,’x’)What is the default file mode in open()?
a) ‘r’ ✅
b) ‘w’
c) ‘a’
d) ‘rb’What does
os.getcwd()return?
a) Current working directory ✅
b) OS name
c) Root directory
d) Home directoryWhich function removes a file?
a) os.remove() ✅
b) delete()
c) os.delete()
d) removefile()What is the output of:
import random
print(random.randint(1,3))
a) Random int 1–3 ✅
b) Always 1
c) Error
d) Float value
Which function is used to get current time?
a) time.time() ✅
b) datetime.now()
c) now.time()
d) current()Which statement is true about tuples?
a) Immutable ✅
b) Mutable
c) Growable
d) DynamicWhich operator repeats a list?
a) * ✅
b) +
c) repeat()
d) loop()What is the result of
[i for i in range(3)]?
a) [0,1,2] ✅
b) (0,1,2)
c) [1,2,3]
d) ErrorWhat is the result of
{x for x in 'aab'}?
a) {‘a’,’b’} ✅
b) [‘a’,’b’]
c) {‘a’,’a’,’b’}
d) ErrorWhich of these is not a keyword in Python?
a) include ✅
b) pass
c) yield
d) globalWhich function returns all Python keywords?
a) keyword.kwlist ✅
b) list.keywords()
c) kwlist()
d) keywords()What is the output of:
print(5 > 3 and 2 < 1)
a) False ✅
b) True
c) Error
d) None
What is the output of:
print(not(2 == 3))
a) True ✅
b) False
c) Error
d) None
Which of the following is a bitwise operator?
a) & ✅
b) &&
c) and
d) |What is the result of:
print(5 & 3)
a) 1 ✅
b) 2
c) 0
d) 3
Which function lists all attributes of an object?
a) dir() ✅
b) list()
c) attr()
d) show()What is the output of:
print(id(10))
a) Memory address ✅
b) 10
c) Type int
d) None
Which module gives access to interpreter variables?
a) sys ✅
b) os
c) platform
d) subprocessWhat does
sys.exit()do?
a) Terminates program ✅
b) Closes file
c) Restarts program
d) Raises exceptionWhat is
repr()used for?
a) Returns string representation for debugging ✅
b) Converts to string for print
c) Prints repr directly
d) Formats textWhat is the result of:
print(sorted({3,1,2}))
a) [1,2,3] ✅
b) {1,2,3}
c) (1,2,3)
d) None
Which function reverses a list in place?
a) reverse() ✅
b) rev()
c) invert()
d) flip()What is the result of
[1,2,3] * 2?
a) [1,2,3,1,2,3] ✅
b) [2,4,6]
c) Error
d) [1,1,2,2,3,3]What does the
map()function do?
a) Applies a function to all items ✅
b) Maps dictionary
c) Creates iterator
d) NoneWhat will
map(int, ['1','2'])return?
a) map object ✅
b) [1,2]
c) (1,2)
d) ErrorWhat is the output of:
list(map(int, ['1','2']))
a) [1,2] ✅
b) map object
c) Error
d) None
What is the result of
filter(None, [0,1,2])?
a) [1,2] ✅
b) [0,1,2]
c) [0]
d) ErrorWhich method removes duplicates from a list?
a) list(set(x)) ✅
b) x.remove_dup()
c) x.unique()
d) x.filter()What will
print(abs(-10))output?
a) 10 ✅
b) -10
c) 0
d) ErrorWhich function returns the largest item in an iterable?
a) max() ✅
b) largest()
c) high()
d) top()What does
divmod(5,2)return?
a) (2,1) ✅
b) (1,2)
c) 2.5
d) ErrorWhat is the output of:
print(pow(2,3))
a) 8 ✅
b) 6
c) 9
d) 4
What is the output of
round(3.75)?
a) 4 ✅
b) 3
c) 3.5
d) 3.8Which function returns True if all items are True?
a) all() ✅
b) any()
c) bool()
d) each()What will be printed by:
print(chr(65))
a) A ✅
b) 65
c) ’65’
d) Error
What is the result of
ord('A')?
a) 65 ✅
b) ‘A’
c) 66
d) NoneWhat is the output of:
print(list(range(2,8,2)))
a) [2,4,6] ✅
b) [2,3,4,5,6,7,8]
c) [2,8]
d) Error
Which statement skips to the next iteration in a loop?
a) continue ✅
b) break
c) pass
d) skipWhich statement exits a loop completely?
a) break ✅
b) exit
c) stop
d) quitWhat is the output of:
for i in range(3): pass
else: print("Done")
a) Done ✅
b) None
c) Error
d) Pass
Which function checks if object is callable?
a) callable() ✅
b) function()
c) type()
d) check()Which module is used to copy objects?
a) copy ✅
b) os
c) shutil
d) pickleWhich function serializes Python objects?
a) pickle.dump() ✅
b) json.save()
c) serialize()
d) write()What is the output of:
print(type(open))
a) builtin_function_or_method ✅
b) function
c) method
d) object
What will
type(3j)output?
a) complex ✅
b) float
c) int
d) imaginaryWhich function converts a string to a list of characters?
a) list(string) ✅
b) split()
c) chars()
d) strlist()
Which operator concatenates two lists?
a) + ✅
b) *
c) &
d) append()What will be the output of:
print([1,2,3] + [4,5])
a) [1, 2, 3, 4, 5] ✅
b) [5, 7, 8]
c) Error
d) [1,2,3],[4,5]
Which Python statement is used to manually raise an exception?
a) raise ✅
b) throw
c) except
d) errorWhat is the output of:
try:
raise ValueError("Oops!")
except ValueError as e:
print(e)
a) Oops! ✅
b) ValueError
c) Error
d) None
Which of these keywords creates a generator expression?
a) yield ✅
b) generate
c) gen
d) returnWhat is the output of:
x = (i*i for i in range(3))
print(next(x))
a) 0 ✅
b) 1
c) 2
d) Error
Which Python module can compress and decompress data?
a) zlib ✅
b) gzip
c) tarfile
d) zipfileWhat is the output of:
print({x:x**2 for x in (2,4,6)})
a) {2: 4, 4: 16, 6: 36} ✅
b) [4,16,36]
c) (2,4,6)
d) Error
Which of these Python features allows executing a block only if the module is run directly?
a) if name == “main“: ✅
b) main():
c) run_main()
d) if name == main():