Python MCQs

  1. Which of the following is the correct extension of a Python file?
    a) .pyth
    b) .pt
    c) .py ✅
    d) .p

  2. What is the output of print(2 ** 3 ** 2)?
    a) 64
    b) 512 ✅
    c) 256
    d) 8

  3. Python is a ___ language.
    a) Compiled
    b) Interpreted ✅
    c) Machine
    d) Assembly

  4. Which of the following is immutable in Python?
    a) List
    b) Dictionary
    c) Tuple ✅
    d) Set

  5. What does len("Python") return?
    a) 5
    b) 6 ✅
    c) 7
    d) Error

  6. What will be the output of:

 
print(type([]) is list)

a) True ✅
b) False
c) list
d) None

  1. What is the output of bool("")?
    a) True
    b) False ✅
    c) Error
    d) None

  2. Which operator is used for floor division?
    a) /
    b) // ✅
    c) %
    d) **

  3. What is the data type of True?
    a) int
    b) bool ✅
    c) str
    d) NoneType

  4. Which of the following statements will create a dictionary?
    a) d = {}
    b) d = []
    c) d = ()
    d) d = set()

  5. What does print(3 * 'ab') output?
    a) ababab ✅
    b) 9
    c) Error
    d) ‘ab3’

  6. 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 begin

  7. Which of these is not a valid keyword?
    a) pass
    b) eval ✅
    c) assert
    d) finally

  8. Which method adds an element to a list?
    a) insert()
    b) add()
    c) append() ✅
    d) push()

  9. 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

  1. 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()

  1. What is the output of print(type( (1,) ))?
    a) tuple ✅
    b) list
    c) int
    d) dict

  2. Which keyword is used to define a function?
    a) func
    b) def ✅
    c) define
    d) function

  3. Which statement is used to exit a loop early?
    a) exit
    b) stop
    c) break ✅
    d) return

  4. How can you comment multiple lines in Python?
    a) /* comment */
    b) # comment
    c) “”” comment “”” ✅
    d) // comment

  5. What does the continue statement do?
    a) Ends loop
    b) Skips iteration ✅
    c) Repeats loop
    d) Exits function

  6. What is the output of print(2 in [1,2,3])?
    a) True ✅
    b) False
    c) None
    d) Error

  7. Which of the following is used to import a module?
    a) load
    b) include
    c) import ✅
    d) require

  8. How do you import only sqrt from math module?
    a) import math.sqrt
    b) from math import sqrt ✅
    c) import sqrt
    d) using math.sqrt

  9. Which function converts a string to lowercase?
    a) lower() ✅
    b) down()
    c) low()
    d) min()

  10. What is the output of print(bool([]))?
    a) True
    b) False ✅
    c) None
    d) Error

  11. What 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) :=

  1. What is the output of "abc" * 2?
    a) abcabc ✅
    b) aabbcc
    c) abc2
    d) Error

  2. Which of the following is NOT a Python data type?
    a) int
    b) float
    c) real ✅
    d) dict

  3. What 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

  1. What will range(3) produce?
    a) [1,2,3]
    b) [0,1,2] ✅
    c) (1,2,3)
    d) Error

  2. What is the output of print(3 > 2 > 1)?
    a) True ✅
    b) False
    c) Error
    d) None

  3. Which built-in function is used to get user input?
    a) scan()
    b) get()
    c) input() ✅
    d) enter()

  4. Which method is used to remove whitespace from both ends of a string?
    a) trim()
    b) strip() ✅
    c) split()
    d) remove()

  5. Which keyword is used for exceptions?
    a) throw
    b) raise ✅
    c) except
    d) try

  6. What is the output of print(type(range(5)))?
    a) list
    b) range ✅
    c) tuple
    d) int

  7. What 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()

  1. Which statement defines a class?
    a) def ClassName:
    b) class ClassName: ✅
    c) define ClassName:
    d) create ClassName:

  2. Which method returns all keys in a dictionary?
    a) getkeys()
    b) allkeys()
    c) keys() ✅
    d) list()

  3. 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

  1. Which of these will raise an error?
    a) 1 + 2
    b) “2” + 3 ✅
    c) 3 * 2
    d) “a” + “b”

  2. What does dict.get(key) return if the key doesn’t exist?
    a) Error
    b) None ✅
    c) False
    d) Empty string

  1. 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

  1. Which of these is not a valid string method?
    a) upper()
    b) replace()
    c) reverse() ✅
    d) join()

  2. How do you create an empty set?
    a) s = {}
    b) s = set() ✅
    c) s = []
    d) s = ()

  3. What is the output of:

 
print(type( (1) ))

a) int ✅
b) tuple
c) list
d) None

  1. Which method adds multiple elements to a list?
    a) add()
    b) extend() ✅
    c) append()
    d) insert()

  2. 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 iterator

  3. What is the output of:

 
x = [1,2,3]
print(x.pop())

a) 1
b) 2
c) 3 ✅
d) Error

  1. How do you define a lambda function?
    a) def x():
    b) lambda x:
    c) func x():
    d) define x:

  2. What is the output of:

 
print(bool("False"))

a) False
b) True ✅
c) Error
d) None

  1. Which of the following is NOT a Python loop?
    a) for
    b) while
    c) loop ✅
    d) nested

  2. What does ord('A') return?
    a) 65 ✅
    b) 66
    c) 64
    d) Error

  3. What does chr(65) return?
    a) A ✅
    b) 65
    c) a
    d) Error

  4. Which keyword is used to inherit a class?
    a) import
    b) extends
    c) class Child(Parent): ✅
    d) inherit

  5. What is the output of:

 
x = [1,2,3]
print(sum(x))

a) 6 ✅
b) 5
c) Error
d) 3

  1. What will print(10//3) output?
    a) 3 ✅
    b) 3.3
    c) 4
    d) 2

  2. Which of these functions converts a value to string?
    a) str() ✅
    b) string()
    c) toString()
    d) chr()

  3. How can you get both index and value while looping through a list?
    a) enumerate() ✅
    b) index()
    c) list()
    d) zip()

  4. What is the output of print(3 * [0])?
    a) [0,0,0] ✅
    b) 000
    c) [3,3,3]
    d) Error

  5. What is the default mode of open() function?
    a) read ✅
    b) write
    c) append
    d) binary

  6. Which method is used to read a single line from a file?
    a) readline() ✅
    b) read()
    c) readlines()
    d) readall()

  7. What will be the output of:

 
x = "Python"
print(x[::-1])

a) nohtyP ✅
b) Python
c) Error
d) pYTHON

  1. What is the output of:

 
x = [1,2,3,4]
print(x[-1])

a) 4 ✅
b) 3
c) Error
d) None

  1. Which of these statements will raise an error?
    a) eval(‘2+3’)
    b) int(‘xyz’) ✅
    c) int(’10’)
    d) float(‘3.14’)

  2. What is the output of:

 
print(all([True, False, True]))

a) True
b) False ✅
c) None
d) Error

  1. What is the output of any([0, "", None, 5])?
    a) True ✅
    b) False
    c) Error
    d) None

  2. What 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

  1. Which of these is a mutable type?
    a) Tuple
    b) List ✅
    c) String
    d) Frozenset

  2. What is the output of:

 
print(10 != 5)

a) True ✅
b) False
c) Error
d) None

  1. Which function returns the number of items in an object?
    a) count()
    b) len() ✅
    c) sum()
    d) size()

  2. What is the output of print(divmod(10,3))?
    a) (3,1) ✅
    b) (3,0)
    c) (10,3)
    d) Error

  3. Which function is used to get the memory location of an object?
    a) address()
    b) location()
    c) id() ✅
    d) get()

  4. 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

  1. Which of the following is used to define anonymous functions?
    a) lambda ✅
    b) def
    c) anon
    d) func

  2. What 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}

  1. What is the output of min([2,5,1,9])?
    a) 9
    b) 2
    c) 1 ✅
    d) 5

  2. What is the output of max('abc')?
    a) a
    b) b
    c) c ✅
    d) Error

  3. What is the result of " ".join(['Python','MCQ'])?
    a) [‘Python’,’MCQ’]
    b) PythonMCQ
    c) Python MCQ ✅
    d) Error

  4. Which keyword is used to skip a block of code without error?
    a) break
    b) continue
    c) pass ✅
    d) skip

  5. What is the output of print(type(lambda x: x))?
    a) function ✅
    b) lambda
    c) object
    d) method

  6. What is the output of print(5 and 0)?
    a) 5
    b) 0 ✅
    c) True
    d) False

  7. Which of the following can’t be used as a variable name?
    a) myVar
    b) _x
    c) True ✅
    d) data1

  8. What is the output of print(list("abc"))?
    a) [‘abc’]
    b) [‘a’,’b’,’c’] ✅
    c) (a,b,c)
    d) Error

  9. Which of the following is used to convert a string into a list of words?
    a) split() ✅
    b) break()
    c) divide()
    d) cut()

  10. 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

  1. Which function gives the type of a variable?
    a) typeof()
    b) type() ✅
    c) gettype()
    d) vartype()

  2. 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

  1. What is the output of abs(-7)?
    a) -7
    b) 7 ✅
    c) 0
    d) Error

  2. What is the output of round(5.678, 2)?
    a) 5.67
    b) 5.68 ✅
    c) 5.6
    d) 5.7

  3. Which of these is a Python built-in module?
    a) os ✅
    b) pandas
    c) requests
    d) flask

  4. What is the output of print(5 is 5)?
    a) True ✅
    b) False
    c) Error
    d) None

  1. 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

  1. What is the output of "Python".find('y')?
    a) 0
    b) 1 ✅
    c) 2
    d) -1

  2. Which of these functions removes duplicates from a list?
    a) list(set(l)) ✅
    b) remove()
    c) unique()
    d) dedup()

  3. What is the output of print(9 // 2)?
    a) 4.5
    b) 4 ✅
    c) 5
    d) 5.0

  4. Which function returns the ASCII value of a character?
    a) ord() ✅
    b) chr()
    c) ascii()
    d) ordval()

  5. What is the output of:

 
x = (1,2,3)
x[0] = 10

a) (10,2,3)
b) Error ✅
c) None
d) [10,2,3]

  1. What is the output of "PYTHON".lower()?
    a) python ✅
    b) PYTHON
    c) Python
    d) Error

  2. Which 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 lists

  3. What does zip() do in Python?
    a) Compress data
    b) Combine iterables ✅
    c) Sort elements
    d) None

  4. Which of the following is used to read all lines from a file?
    a) read()
    b) readline()
    c) readlines() ✅
    d) scanlines()

  5. What is the output of:

 
print(bool(None))

a) True
b) False ✅
c) None
d) Error

  1. What is the output of:

 
print(4**(1/2))

a) 2 ✅
b) 4
c) 8
d) 16

  1. Which function is used to sort a list permanently?
    a) sort() ✅
    b) sorted()
    c) order()
    d) arrange()

  2. What is the output of sorted([3,1,2])?
    a) [1,2,3] ✅
    b) [3,2,1]
    c) [3,1,2]
    d) Error

  3. What is the output of:

 
print(type(True + False))

a) bool
b) int ✅
c) str
d) Error

  1. Which method is used to remove an item by value from a list?
    a) delete()
    b) remove() ✅
    c) pop()
    d) discard()

  2. What will print(10 % 3) output?
    a) 1 ✅
    b) 3
    c) 0
    d) Error

  3. What does x, y = y, x do in Python?
    a) Swaps x and y ✅
    b) Compares x and y
    c) Duplicates x
    d) None

  4. What is the output of "abc".upper()?
    a) abc
    b) ABC ✅
    c) Abc
    d) Error

  5. What is the output of "abc".capitalize()?
    a) abc
    b) Abc ✅
    c) ABC
    d) aBC

  6. What does list('123') return?
    a) [1,2,3]
    b) [‘1′,’2′,’3’] ✅
    c) [‘123’]
    d) Error

  7. Which 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)

  8. What is the output of:

 
x = [1,2,3]
print(len(x))

a) 3 ✅
b) 2
c) 4
d) Error

  1. What does help(len) do?
    a) Prints documentation ✅
    b) Runs len()
    c) Counts help
    d) Error

  2. What is the output of:

 
print(type( (1,2,3) ))

a) tuple ✅
b) list
c) set
d) dict

  1. What is the output of print(2 ** 4)?
    a) 8
    b) 16 ✅
    c) 4
    d) 32

  2. What is the output of:

 
print("a" in "apple")

a) True ✅
b) False
c) Error
d) None

  1. Which function returns the absolute value of a number?
    a) fabs()
    b) abs() ✅
    c) absolute()
    d) val()

  2. What is the output of:

 
x = {"a":1, "b":2}
print("a" in x)

a) True ✅
b) False
c) Error
d) None

  1. 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

  1. Which of these keywords defines an empty block?
    a) continue
    b) break
    c) pass ✅
    d) return

  2. What is the output of "Python"[1:4]?
    a) Pyt
    b) yth ✅
    c) ytho
    d) hyt

  3. What is the output of print(len(set("banana")))?
    a) 6
    b) 3 ✅
    c) 4
    d) 2

  4. Which method returns the number of occurrences of a substring?
    a) count() ✅
    b) find()
    c) index()
    d) occurrences()

  5. 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

  1. Which function converts string to integer safely?
    a) str()
    b) eval()
    c) int() ✅
    d) input()

  2. What is the output of:

 
print(5 > 3 and 2 < 1)

a) True
b) False ✅
c) Error
d) None

  1. What will print(type([]) == list) return?
    a) True ✅
    b) False
    c) None
    d) Error

  2. What is the output of print(not 0)?
    a) True ✅
    b) False
    c) None
    d) 0

  3. What is the output of:

 
print(bool(" "))

a) False
b) True ✅
c) None
d) Error

  1. What will len({1: "a", 2: "b"}) return?
    a) 1
    b) 2 ✅
    c) 0
    d) 3

  2. Which keyword is used to define a generator?
    a) yield ✅
    b) gen
    c) lambda
    d) next

  3. What 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

  1. What is the output of print(sum([1,2,3,4]))?
    a) 9
    b) 10 ✅
    c) 8
    d) Error

  2. What is the output of print(3*'ab')?
    a) ababab ✅
    b) abab
    c) 3ab
    d) Error

  3. Which 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 slicing

  4. What will print(5 == 5.0) output?
    a) True ✅
    b) False
    c) None
    d) Error

  5. What is the output of list(range(0))?
    a) [] ✅
    b) [0]
    c) [1]
    d) Error

  6. What is the output of print("abc" + "def")?
    a) abcdef ✅
    b) abc def
    c) abc+def
    d) Error

  7. Which built-in function can execute a string as code?
    a) exec() ✅
    b) run()
    c) evalstr()
    d) compile()

  1. 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 m

  2. What is the output of:

 
print(pow(2,3))

a) 6
b) 8 ✅
c) 9
d) Error

  1. What is the output of:

 
print(type({1,2,3}))

a) list
b) set ✅
c) dict
d) tuple

  1. Which statement will raise an exception?
    a) int(‘123’)
    b) int(‘abc’) ✅
    c) float(‘2.5’)
    d) str(25)

  2. What is the output of:

 
x = [1,2,3]
print(x*0)

a) [] ✅
b) [0,0,0]
c) [1,2,3]
d) Error

  1. What will print("Hello {}".format("World")) output?
    a) Hello World ✅
    b) Hello {}
    c) Hello ‘World’
    d) Error

  2. What does locals() return?
    a) Dictionary of local variables ✅
    b) List of global variables
    c) Memory address
    d) None

  3. What does globals() return?
    a) Global namespace ✅
    b) Local namespace
    c) Modules
    d) Environment variables

  4. What is the output of:

 
print(10 > 5 or 2 > 3)

a) True ✅
b) False
c) Error
d) None

  1. Which of the following creates a tuple with one element?
    a) (1,) ✅
    b) (1)
    c) [1,]
    d) {1,}

  2. What is the output of:

 
print('a' * 3)

a) a
b) aaa ✅
c) 3a
d) Error

  1. Which statement is true about Python lists?
    a) They are immutable
    b) They are ordered ✅
    c) They are sets
    d) They can’t contain duplicates

  2. What is the output of:

 
print(isinstance(5, int))

a) True ✅
b) False
c) None
d) Error

  1. Which module is used for random number generation?
    a) random ✅
    b) math
    c) os
    d) sys

  2. What is the output of:

 
import random
print(type(random.random()))

a) int
b) float ✅
c) str
d) NoneType

  1. What is the output of:

 
print("abc".replace("a","z"))

a) zbc ✅
b) abc
c) azc
d) zcc

  1. Which function finds the minimum value from arguments?
    a) min() ✅
    b) smallest()
    c) least()
    d) low()

  2. Which of the following statements is invalid?
    a) x = 10
    b) 10 = x ✅
    c) x, y = 1, 2
    d) x += 5

  3. What does dir() function do?
    a) Lists all attributes/methods ✅
    b) Lists directories
    c) Returns documentation
    d) Deletes variables

  4. What is the output of:

 
print(type(10.0))

a) int
b) float ✅
c) decimal
d) number

  1. Which keyword is used to define a class?
    a) def
    b) class ✅
    c) define
    d) object

  2. What is the output of:

 
x = {1:'a', 2:'b'}
print(x[2])

a) 1
b) a
c) b ✅
d) Error

  1. What is the output of:

 
print(bool([]) == False)

a) True ✅
b) False
c) None
d) Error

  1. What is the result of:

 
print(3 in [1,2,3,4])

a) True ✅
b) False
c) Error
d) None

  1. What is the output of:

 
x = [1,2,3]
print(x[-2])

a) 2 ✅
b) 3
c) 1
d) Error

  1. What is the output of:

 
print(3 * (1 + 2))

a) 9 ✅
b) 6
c) 5
d) 3

  1. What is the output of "hello".title()?
    a) Hello ✅
    b) HELLO
    c) hello
    d) hELLO

  2. Which built-in function returns the largest integer ≤ x?
    a) ceil()
    b) floor() ✅
    c) round()
    d) trunc()

  3. Which module contains floor()?
    a) random
    b) math ✅
    c) sys
    d) time

  4. What does isinstance("abc", str) return?
    a) True ✅
    b) False
    c) None
    d) Error

  5. Which statement is correct about Python indentation?
    a) It’s optional
    b) It defines blocks ✅
    c) It’s ignored
    d) It must use tabs only

  6. What is the output of:

 
print(5 | 3)

a) 1
b) 7 ✅
c) 15
d) 8

  1. What is the output of:

 
print(5 & 3)

a) 7
b) 1 ✅
c) 0
d) 8

  1. Which bitwise operator inverts bits?
    a) ~ ✅
    b) ^
    c) |
    d) &

  2. What is the output of:

 
print(~2)

a) -3 ✅
b) -2
c) 3
d) 2

  1. What is the output of:

 
print(2 << 1)

a) 4 ✅
b) 1
c) 2
d) 8

  1. What is the output of:

 
print(8 >> 2)

a) 2 ✅
b) 4
c) 8
d) 1

  1. Which function is used to get the current working directory?
    a) os.getcwd() ✅
    b) sys.getcwd()
    c) os.current()
    d) os.path()

  2. What is the output of:

 
x = "Python"
print(len(x))

a) 5
b) 6 ✅
c) 7
d) Error

  1. Which function is used to remove a key from a dictionary?
    a) pop() ✅
    b) remove()
    c) delete()
    d) discard()

  2. What is the output of "abc".isalpha()?
    a) True ✅
    b) False
    c) Error
    d) None

  3. What is the output of "123".isdigit()?
    a) True ✅
    b) False
    c) Error
    d) None

  4. Which function can reverse a list?
    a) reverse() ✅
    b) flip()
    c) turn()
    d) rev()

  5. What is the output of list(reversed([1,2,3]))?
    a) [3,2,1] ✅
    b) [1,2,3]
    c) Error
    d) None

  6. Which function returns both index and element in a loop?
    a) enumerate() ✅
    b) index()
    c) items()
    d) zip()

  7. 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

  1. Which function checks if all elements are True?
    a) all() ✅
    b) any()
    c) bool()
    d) check()

  2. What is the output of any([0, 1, 0])?
    a) True ✅
    b) False
    c) None
    d) Error

  3. Which 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+2

  4. What 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

  1. 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

  1. 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))

  2. What is the output of print(sum([True, False, True]))?
    a) 1
    b) 2 ✅
    c) 3
    d) 0

  3. What 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]

  1. Which function returns the maximum of iterable values?
    a) max() ✅
    b) large()
    c) greatest()
    d) big()

  2. 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

  1. What is the output of divmod(9,2)?
    a) (4,1) ✅
    b) (4,2)
    c) (4.5,0)
    d) Error

  2. Which function checks if an object is callable?
    a) callable() ✅
    b) call()
    c) iscall()
    d) func()

  3. What is the output of:

 
x = lambda a,b: a*b
print(x(2,3))

a) 6 ✅
b) 5
c) Error
d) 23

  1. 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

  1. What is the output of "python".startswith("py")?
    a) True ✅
    b) False
    c) None
    d) Error

  2. What does enumerate(["a","b","c"]) return?
    a) [(0,”a”),(1,”b”),(2,”c”)] ✅
    b) [0,”a”,”b”,”c”]
    c) (0,”a”,”b”,”c”)
    d) None

  3. Which function returns a new list sorted without modifying the original?
    a) sorted() ✅
    b) sort()
    c) arrange()
    d) order()

  4. What is the output of:

 
print(bool('False'))

a) True ✅
b) False
c) Error
d) None

  1. 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

  1. Which of these methods belongs to a string object?
    a) split() ✅
    b) push()
    c) add()
    d) extend()

  2. What is the output of "Python".index("t")?
    a) 2 ✅
    b) 3
    c) 1
    d) Error

  3. What will "Python".count("P") return?
    a) 0
    b) 1 ✅
    c) 2
    d) Error

  4. Which function gives the absolute difference between two sets?
    a) symmetric_difference() ✅
    b) difference()
    c) union()
    d) intersection()

  5. 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) {}

  1. What is the output of:

 
print({1,2,3}.issubset({1,2,3,4}))

a) True ✅
b) False
c) None
d) Error

  1. What is the output of "abc" * 0?
    a) ” ✅
    b) abc
    c) 0
    d) Error

  2. Which method adds multiple items to a list?
    a) append()
    b) extend() ✅
    c) insert()
    d) add()

  3. Which of these is used to catch exceptions?
    a) try…except ✅
    b) catch()
    c) handle()
    d) stop()

  4. What is the output of:

 
try:
print(1/0)
except ZeroDivisionError:
print("error")

a) 1/0
b) error ✅
c) ZeroDivisionError
d) None

  1. What is the output of:

 
try:
pass
finally:
print("done")

a) done ✅
b) Error
c) None
d) pass

  1. What is the output of type(5j)?
    a) complex ✅
    b) float
    c) int
    d) imaginary

  2. Which operator is used for identity comparison?
    a) is ✅
    b) ==
    c) ===
    d) eq

  3. What is the output of:

 
x = [1,2]
y = [1,2]
print(x is y)

a) True
b) False ✅
c) None
d) Error

  1. What is the output of type(range(5))?
    a) list
    b) range ✅
    c) generator
    d) iterator

  2. What is the output of:

 
print(" ".join(["a","b","c"]))

a) “a b c” ✅
b) “abc”
c) “a,b,c”
d) Error

  1. What will "PYTHON".isupper() return?
    a) True ✅
    b) False
    c) Error
    d) None

  2. What will "py".islower() return?
    a) True ✅
    b) False
    c) None
    d) Error

  3. Which method removes whitespace from both ends of a string?
    a) strip() ✅
    b) trim()
    c) remove()
    d) cut()

  4. What is the output of "abc".replace("a","")?
    a) “bc” ✅
    b) “a”
    c) “abc”
    d) “”

  5. What is the output of:

 
print(len(" "))

a) 0
b) 1 ✅
c) 2
d) Error

  1. What is the output of:

 
print(bool([] and [1]))

a) True
b) False ✅
c) []
d) Error

  1. What is the output of:

 
print(bool([] or [1]))

a) []
b) [1] ✅
c) True
d) False

  1. Which operator checks membership?
    a) in ✅
    b) is
    c) ==
    d) has

  2. Which module handles JSON in Python?
    a) json ✅
    b) os
    c) pickle
    d) text

  3. What is the output of:

 
import json
print(type(json.dumps({"a":1})))

a) str ✅
b) dict
c) bytes
d) None

  1. Which function converts JSON string to Python object?
    a) json.loads() ✅
    b) json.dumps()
    c) json.read()
    d) json.convert()

  2. Which function converts Python object to JSON string?
    a) json.dumps() ✅
    b) json.loads()
    c) json.write()
    d) json.jsonify()

  3. What is the output of:

 
a = [1,2,3]
b = a.copy()
print(a is b)

a) True
b) False ✅
c) None
d) Error

  1. Which of these creates an empty dictionary?
    a) {} ✅
    b) []
    c) set()
    d) dict[]

  2. Which statement is used to exit a loop?
    a) break ✅
    b) exit
    c) pass
    d) stop

  3. Which function returns a sorted list of dictionary keys?
    a) sorted(dict.keys()) ✅
    b) sort(dict.keys())
    c) dict.sort()
    d) order(dict)

  4. 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

  1. 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

  1. Which keyword is used to inherit a class?
    a) class Child(Base): ✅
    b) inherit Base
    c) Base -> Child
    d) extends Base

  2. What 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

  1. What will getattr(a, 'x', 0) return if attribute x doesn’t exist?
    a) 0 ✅
    b) None
    c) Error
    d) False

  2. Which method is called when an object is created?
    a) new()
    b) init() ✅
    c) start()
    d) create()

  3. Which method returns a string representation of an object?
    a) repr() ✅
    b) str()
    c) name()
    d) display()

  4. What is the output of:

 
print(bool(0.000))

a) False ✅
b) True
c) 0.000
d) Error

  1. 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

  1. What is __name__ when a Python script is run directly?
    a) “main” ✅
    b) script
    c) function
    d) None

  2. What is the output of isinstance(True, int)?
    a) True ✅
    b) False
    c) Error
    d) None

  3. Which of the following functions imports a module dynamically?
    a) import() ✅
    b) importlib()
    c) execimport()
    d) import()

  4. Which exception is raised for invalid index access?
    a) IndexError ✅
    b) KeyError
    c) ValueError
    d) NameError

  5. Which exception occurs when converting a non-numeric string to int?
    a) ValueError ✅
    b) TypeError
    c) SyntaxError
    d) NameError

  6. What is the output of:

 
try:
x = 1/0
except Exception as e:
print(type(e).__name__)

a) ZeroDivisionError ✅
b) Exception
c) Error
d) None

  1. Which function checks memory location of an object?
    a) id() ✅
    b) loc()
    c) address()
    d) ref()

  2. What is the output of:

 
x = [1,2,3]
print(x.pop())

a) 3 ✅
b) 2
c) [1,2]
d) Error

  1. What does the with statement do?
    a) Manages context (auto close resources) ✅
    b) Declares function
    c) Imports module
    d) Creates loop

  2. What 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

  1. What is the output of:

 
import math
print(math.ceil(4.2))

a) 4
b) 5 ✅
c) 4.2
d) 6

  1. Which module is used to work with dates and times?
    a) datetime ✅
    b) time
    c) calendar
    d) os

  2. What does datetime.date.today() return?
    a) Current date ✅
    b) Current time
    c) Timestamp
    d) String

  3. Which function pauses program execution?
    a) time.sleep() ✅
    b) wait()
    c) pause()
    d) stop()

  4. Which module provides command-line arguments?
    a) sys ✅
    b) os
    c) argparse
    d) getopt

  5. What is the output of:

 
import sys
print(sys.version_info.major)

a) Python major version ✅
b) sys info
c) 3.x.x
d) Error

  1. Which function removes and returns last element of a list?
    a) pop() ✅
    b) del()
    c) remove()
    d) drop()

  2. Which function creates an iterator from multiple iterables?
    a) zip() ✅
    b) join()
    c) map()
    d) list()

  3. 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]

  1. Which function executes code from a file?
    a) exec(open(“file.py”).read()) ✅
    b) run(“file.py”)
    c) import file
    d) os.run()

  2. What does input() return?
    a) Always a string ✅
    b) int if numeric
    c) Depends on input
    d) None

  3. What is the output of:

 
print("abc".center(7, "-"))

a) –abc– ✅
b) -abc-
c) abc—-
d) —abc

  1. Which module supports regular expressions?
    a) re ✅
    b) regex
    c) pattern
    d) match

  2. What 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

  1. What is the output of:

 
print(",".join(map(str,[1,2,3])))

a) 1,2,3 ✅
b) [1,2,3]
c) 123
d) Error

  1. What is the output of:

 
print(hex(255))

a) 0xff ✅
b) ff
c) 255
d) 0x255

  1. What is the output of bin(8)?
    a) 0b1000 ✅
    b) 1000
    c) 8
    d) 0b8

  2. Which function converts integer to octal string?
    a) oct() ✅
    b) hex()
    c) bin()
    d) str()

  3. 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’)

  4. What is the output of:

 
a = [1,2,3]
print(next(iter(a)))

a) 1 ✅
b) 2
c) 3
d) Error

  1. Which statement correctly defines a generator?
    a) yield keyword inside a function ✅
    b) def with return
    c) lambda function
    d) class with iter

  2. What is the output of:

 
def gen():
yield 1
yield 2
print(list(gen()))

a) [1,2] ✅
b) [2,1]
c) [1]
d) Error

  1. What does next() do on an iterator?
    a) Returns next item ✅
    b) Resets iterator
    c) Repeats last
    d) Deletes item

  2. Which module provides system-level operations like file paths?
    a) os ✅
    b) sys
    c) path
    d) shutil

  3. What is the output of:

 
import os
print(os.path.basename("/user/bin/python"))

a) python ✅
b) bin
c) user
d) /python

  1. What is the output of:

 
print(round(5.678, 2))

a) 5.68 ✅
b) 5.67
c) 5.6
d) 6.0

  1. Which of these functions shuffles a list randomly?
    a) random.shuffle() ✅
    b) random.mix()
    c) randomize()
    d) random.change()

  2. What is the output of:

 
print(all([1,2,0]))

a) True
b) False ✅
c) Error
d) None

  1. Which statement is true for decorators?
    a) They modify function behavior ✅
    b) They compile code
    c) They change return type
    d) They execute asynchronously

  2. What 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

  1. Which keyword is used to define an anonymous block that does nothing?
    a) pass ✅
    b) null
    c) continue
    d) nop

  2. What 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

  1. Which keyword is used to create an inline anonymous function?
    a) lambda ✅
    b) def
    c) anon
    d) func

  2. What will be the result of:

 
print('Python'.find('y'))

a) 1 ✅
b) 0
c) 2
d) -1

  1. What is the output of:

 
print('Hello' * 3)

a) HelloHelloHello ✅
b) Hello3
c) Error
d) None

  1. Which of the following is used to define a block of code in Python?
    a) Indentation ✅
    b) Braces {}
    c) Parentheses ()
    d) Semicolons

  2. What does max([3,5,2,8]) return?
    a) 8 ✅
    b) 3
    c) 2
    d) 5

  3. Which of these is a valid variable name?
    a) my_var ✅
    b) 1var
    c) var-1
    d) my var

  4. What will print(bool('False')) output?
    a) True ✅
    b) False
    c) ‘False’
    d) None

  5. What 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]

  1. What is the type of the object created by range(5)?
    a) range ✅
    b) list
    c) tuple
    d) iterator

  2. What will bool([]) return?
    a) False ✅
    b) True
    c) None
    d) Error

  3. Which function returns the number of elements in an object?
    a) len() ✅
    b) count()
    c) size()
    d) total()

  4. What is the output of:

 
print(10 // 3)

a) 3 ✅
b) 3.33
c) 4
d) Error

  1. What is the output of 2 == 2.0?
    a) True ✅
    b) False
    c) Error
    d) None

  2. Which statement is true about Python lists?
    a) Lists are mutable ✅
    b) Lists are immutable
    c) Lists store only numbers
    d) Lists are fixed-length

  3. Which of the following is a Python tuple?
    a) (1,2,3) ✅
    b) [1,2,3]
    c) {1,2,3}
    d) tuple[1,2,3]

  4. What will print(type({})) output?
    a) <class ‘dict’> ✅
    b) <class ‘set’>
    c) <class ‘list’>
    d) None

  5. Which method adds an element to a set?
    a) add() ✅
    b) append()
    c) insert()
    d) push()

  6. What is the output of:

 
print(bool(None))

a) False ✅
b) True
c) None
d) Error

  1. Which of these is a correct dictionary declaration?
    a) {‘a’:1, ‘b’:2} ✅
    b) {1,2,3}
    c) [‘a’,1]
    d) (‘a’:1)

  2. What is the output of:

 
d = {'a':1,'b':2}
print(d.get('c', 0))

a) 0 ✅
b) None
c) Error
d) ‘c’

  1. Which function returns all keys in a dictionary?
    a) keys() ✅
    b) values()
    c) items()
    d) get()

  2. What will list("abc") produce?
    a) [‘a’,’b’,’c’] ✅
    b) [‘abc’]
    c) (‘a’,’b’,’c’)
    d) Error

  3. What does enumerate(['a','b']) return?
    a) Iterator of (index, value) pairs ✅
    b) List of tuples
    c) Dictionary
    d) None

  4. What is the output of:

 
print(any([0, False, 3]))

a) True ✅
b) False
c) 3
d) Error

  1. Which of the following removes whitespace from both ends of a string?
    a) strip() ✅
    b) trim()
    c) remove()
    d) clean()

  2. What is the output of:

 
print('python'.capitalize())

a) Python ✅
b) python
c) PYTHON
d) None

  1. Which function converts string to lowercase?
    a) lower() ✅
    b) down()
    c) casefold()
    d) reduce()

  2. What is the output of:

 
print('PYTHON'.lower())

a) python ✅
b) PYTHON
c) None
d) Error

  1. Which method checks if a string starts with a specific substring?
    a) startswith() ✅
    b) begins()
    c) prefix()
    d) check()

  2. Which method returns the index of a substring?
    a) find() ✅
    b) locate()
    c) indexof()
    d) position()

  3. What is the output of:

 
print('abc'.upper())

a) ABC ✅
b) abc
c) None
d) Error

  1. Which statement defines a function in Python?
    a) def func(): ✅
    b) function func():
    c) define func():
    d) func def():

  2. What is the output of:

 
def f(x=5): return x+1
print(f())

a) 6 ✅
b) 5
c) Error
d) None

  1. Which keyword is used to return a value from a function?
    a) return ✅
    b) yield
    c) pass
    d) end

  2. What is the output of:

 
x = lambda a,b : a+b
print(x(2,3))

a) 5 ✅
b) 6
c) Error
d) 2+3

  1. What is recursion in Python?
    a) Function calling itself ✅
    b) Nested loops
    c) Class inheritance
    d) None

  2. What 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

  1. Which function returns documentation string of a function?
    a) help() ✅
    b) doc()
    c) info()
    d) describe()

  2. What is the output of:

 
print(3 in [1,2,3])

a) True ✅
b) False
c) Error
d) None

  1. What will happen if you divide by zero?
    a) ZeroDivisionError ✅
    b) ValueError
    c) TypeError
    d) None

  2. What is the output of:

 
try:
print(1/1)
except:
print("Error")
else:
print("OK")

a) 1.0 OK ✅
b) Error
c) OK
d) None

  1. What is the output of:

 
a = [1,2,3]
print(sum(a))

a) 6 ✅
b) 123
c) Error
d) None

  1. Which statement reads an entire file as a string?
    a) f.read() ✅
    b) f.readline()
    c) f.readlines()
    d) file.read()

  2. 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’)

  3. What is the default file mode in open()?
    a) ‘r’ ✅
    b) ‘w’
    c) ‘a’
    d) ‘rb’

  4. What does os.getcwd() return?
    a) Current working directory ✅
    b) OS name
    c) Root directory
    d) Home directory

  5. Which function removes a file?
    a) os.remove() ✅
    b) delete()
    c) os.delete()
    d) removefile()

  6. 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

  1. Which function is used to get current time?
    a) time.time() ✅
    b) datetime.now()
    c) now.time()
    d) current()

  2. Which statement is true about tuples?
    a) Immutable ✅
    b) Mutable
    c) Growable
    d) Dynamic

  3. Which operator repeats a list?
    a) * ✅
    b) +
    c) repeat()
    d) loop()

  4. What is the result of [i for i in range(3)]?
    a) [0,1,2] ✅
    b) (0,1,2)
    c) [1,2,3]
    d) Error

  5. What is the result of {x for x in 'aab'}?
    a) {‘a’,’b’} ✅
    b) [‘a’,’b’]
    c) {‘a’,’a’,’b’}
    d) Error

  6. Which of these is not a keyword in Python?
    a) include ✅
    b) pass
    c) yield
    d) global

  7. Which function returns all Python keywords?
    a) keyword.kwlist ✅
    b) list.keywords()
    c) kwlist()
    d) keywords()

  8. What is the output of:

 
print(5 > 3 and 2 < 1)

a) False ✅
b) True
c) Error
d) None

  1. What is the output of:

 
print(not(2 == 3))

a) True ✅
b) False
c) Error
d) None

  1. Which of the following is a bitwise operator?
    a) & ✅
    b) &&
    c) and
    d) |

  2. What is the result of:

 
print(5 & 3)

a) 1 ✅
b) 2
c) 0
d) 3

  1. Which function lists all attributes of an object?
    a) dir() ✅
    b) list()
    c) attr()
    d) show()

  2. What is the output of:

 
print(id(10))

a) Memory address ✅
b) 10
c) Type int
d) None

  1. Which module gives access to interpreter variables?
    a) sys ✅
    b) os
    c) platform
    d) subprocess

  2. What does sys.exit() do?
    a) Terminates program ✅
    b) Closes file
    c) Restarts program
    d) Raises exception

  3. What is repr() used for?
    a) Returns string representation for debugging ✅
    b) Converts to string for print
    c) Prints repr directly
    d) Formats text

  4. What is the result of:

 
print(sorted({3,1,2}))

a) [1,2,3] ✅
b) {1,2,3}
c) (1,2,3)
d) None

  1. Which function reverses a list in place?
    a) reverse() ✅
    b) rev()
    c) invert()
    d) flip()

  2. 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]

  3. What does the map() function do?
    a) Applies a function to all items ✅
    b) Maps dictionary
    c) Creates iterator
    d) None

  4. What will map(int, ['1','2']) return?
    a) map object ✅
    b) [1,2]
    c) (1,2)
    d) Error

  5. What is the output of:

 
list(map(int, ['1','2']))

a) [1,2] ✅
b) map object
c) Error
d) None

  1. What is the result of filter(None, [0,1,2])?
    a) [1,2] ✅
    b) [0,1,2]
    c) [0]
    d) Error

  2. Which method removes duplicates from a list?
    a) list(set(x)) ✅
    b) x.remove_dup()
    c) x.unique()
    d) x.filter()

  3. What will print(abs(-10)) output?
    a) 10 ✅
    b) -10
    c) 0
    d) Error

  4. Which function returns the largest item in an iterable?
    a) max() ✅
    b) largest()
    c) high()
    d) top()

  5. What does divmod(5,2) return?
    a) (2,1) ✅
    b) (1,2)
    c) 2.5
    d) Error

  6. What is the output of:

 
print(pow(2,3))

a) 8 ✅
b) 6
c) 9
d) 4

  1. What is the output of round(3.75)?
    a) 4 ✅
    b) 3
    c) 3.5
    d) 3.8

  2. Which function returns True if all items are True?
    a) all() ✅
    b) any()
    c) bool()
    d) each()

  3. What will be printed by:

 
print(chr(65))

a) A ✅
b) 65
c) ’65’
d) Error

  1. What is the result of ord('A')?
    a) 65 ✅
    b) ‘A’
    c) 66
    d) None

  2. What 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

  1. Which statement skips to the next iteration in a loop?
    a) continue ✅
    b) break
    c) pass
    d) skip

  2. Which statement exits a loop completely?
    a) break ✅
    b) exit
    c) stop
    d) quit

  3. What is the output of:

 
for i in range(3): pass
else: print("Done")

a) Done ✅
b) None
c) Error
d) Pass

  1. Which function checks if object is callable?
    a) callable() ✅
    b) function()
    c) type()
    d) check()

  2. Which module is used to copy objects?
    a) copy ✅
    b) os
    c) shutil
    d) pickle

  3. Which function serializes Python objects?
    a) pickle.dump() ✅
    b) json.save()
    c) serialize()
    d) write()

  4. What is the output of:

 
print(type(open))

a) builtin_function_or_method ✅
b) function
c) method
d) object

  1. What will type(3j) output?
    a) complex ✅
    b) float
    c) int
    d) imaginary

  2. Which function converts a string to a list of characters?
    a) list(string) ✅
    b) split()
    c) chars()
    d) strlist()

  1. Which operator concatenates two lists?
    a) + ✅
    b) *
    c) &
    d) append()

  2. 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]

  1. Which Python statement is used to manually raise an exception?
    a) raise ✅
    b) throw
    c) except
    d) error

  2. What is the output of:

 
try:
raise ValueError("Oops!")
except ValueError as e:
print(e)

a) Oops! ✅
b) ValueError
c) Error
d) None

  1. Which of these keywords creates a generator expression?
    a) yield ✅
    b) generate
    c) gen
    d) return

  2. What is the output of:

 
x = (i*i for i in range(3))
print(next(x))

a) 0 ✅
b) 1
c) 2
d) Error

  1. Which Python module can compress and decompress data?
    a) zlib ✅
    b) gzip
    c) tarfile
    d) zipfile

  2. What 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

  1. 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():

You cannot copy content of this page

Scroll to Top