PYTHON MCQs QUESTIONS & ANSWERS
Section 1: Python Basics & Data Types (50 MCQs)
Q1. What is the output of print(type(5/2))?
D) complex C) double B) float A) int
Answer: B) float
Q2. Which keyword is used to define a function in Python?
D) function C) def B) define A) func
Answer: C) def
Q3. What is the result of 3 * 1 ** 3?
D) 1 C) 27 B) 9 A) 3
Answer: A) 3
Q4. Which of the following is a valid variable name?
D) for C) name$ B) _name A) 2name
Answer: B) _name
Q5. Output of print(bool(0), bool(3.14), bool(''))?
D) True True True C) False False True B) True False True A) False True False
Answer: A) False True False
Q6. id() function returns what?
D) Type C) Index B) Value A) Memory address
Answer: A) Memory address
Q7. Output of print(2 ** 3 ** 2)?
D) 8 C) 256 B) 512 A) 64
Answer: B) 512
Q8. In Python 3, integer division uses which operator?
D) % C) \ B) // A) /
Answer: B) //
Q9. Output of print(10 % 3)?
D) 10 C) 0.1 B) 3 A) 1
Answer: A) 1
Q10. Which function gives the data type of a variable?
D) id() C) type() B) checktype() A) datatype()
Answer: C) type()
Q11. Which of these is immutable?
D) set C) dict B) tuple A) list
Answer: B) tuple
Q12. What is the default value of an uninitialized variable in Python?
D) No default – must assign before use C) Null B) 0 A) None
Answer: D) No default – must assign before use
Q13. What is the output of print(5==5.0)?
D) None C) Error B) True A) False
Answer: B) True
Q14. Approximately how many keywords are there in Python 3.10?
D) 50 C) 35 B) 30 A) 25
Answer: C) 35
Q15. The is operator checks for:
D) Comparison C) Membership B) Object identity A) Value equality
Answer: B) Object identity
Q16. The == operator checks for:
D) Assignment C) Membership B) Value equality A) Object identity
Answer: B) Value equality
Q17. Output of print(type(True))?
A) <class 'str'>B) <class 'int'>C) <class 'bool'>D) <class 'float'>
Answer: C) <class 'bool'>
Q18. Which symbol starts a comment?
D) -- C) /* B) # A) //
Answer: B) #
Q19. Multi-line strings are enclosed within:
D) Double quotes C) Parentheses B) Triple quotes A) Single quotes
Answer: B) Triple quotes
Q20. Output of print("CDAC\nPGDBDA")?
C) B) CDAC PGDBDA A) CDAC\nPGDBDA
CDAC
PGDBDA
D) Error
Answer: C
Q21. Output of print("A", "B", "C", sep='-')?
D) A--B--C C) A B C B) A-B-C A) ABC
Answer: B) A-B-C
Q22. Which function takes user input as a string?
D) raw_input() C) get() B) input() A) read()
Answer: B) input()
Q23. Convert string to integer:
D) eval() C) int() B) float() A) str()
Answer: C) int()
Q24. Output of print(5 < 6 < 7)?
D) None C) Error B) False A) True
Answer: A) True
Q25. What is dynamic typing?
D) None C) Static typing B) Type decided at runtime A) Type fixed at compile time
Answer: B) Type decided at runtime
Q26. Output of type(3 + 4j)?
D) tuple C) complex B) float A) int
Answer: C) complex
Q27. None represents:
D) Boolean False C) Absence of a value B) 0 A) Empty string
Answer: C) Absence of a value
Q28. What will print(0.1 + 0.2 == 0.3) output?
D) 0.3 C) Error B) False A) True
Answer: B) False
Q29. Which built-in converts decimal to binary string?
D) str() C) hex() B) binary() A) bin()
Answer: A) bin()
Q30. oct(8) returns?
D) Error C) 10 B) '0o10' A) '010'
Answer: B) '0o10'
Q31. hex(15) returns?
D) '15h' C) '0xf' B) '0x15' A) '15'
Answer: C) '0xf'
Q32. Python files have which extension?
D) .pt C) .python B) .p A) .py
Answer: A) .py
Q33. Output of print(10/4)?
D) Error C) 2.5 B) 2.0 A) 2
Answer: C) 2.5
Q34. Output of print(10//4)?
D) Error C) 3 B) 2.5 A) 2
Answer: A) 2
Q35. Output of print(2**3)?
D) 16 C) 9 B) 8 A) 6
Answer: B) 8
Q36. Expression 4 + 3 * 2 evaluates to:
D) 8 C) 16 B) 10 A) 14
Answer: B) 10
Q37. round(5.678, 2) = ?
D) 6.0 C) 5.68 B) 5.67 A) 5.6
Answer: C) 5.68
Q38. Which function checks variable type?
D) check() C) type() B) isinstance() A) id()
Answer: C) type()
Q39. To check if variable is instance of class:
D) attr(x) C) id(x) B) isinstance(x, classname) A) type(x)
Answer: B) isinstance(x, classname)
Q40. del x does what?
D) Prints error C) Converts to None B) Clears memory A) Deletes variable reference
Answer: A) Deletes variable reference
Q41. Which function returns length?
D) length() C) count() B) size() A) len()
Answer: A) len()
Q42. Output of len("CDAC")?
D) Error C) 5 B) 4 A) 3
Answer: B) 4
Q43. print(3 > 2 and 2 > 1) → ?
D) Error C) None B) False A) True
Answer: A) True
Q44. print(3 > 2 or 2 > 5) → ?
D) Error C) None B) False A) True
Answer: A) True
Q45. print(not False) → ?
D) Error C) None B) True A) False
Answer: B) True
Q46. What is Python’s main implementation called?
D) PyPy C) CPython B) IronPython A) Jython
Answer: C) CPython
Q47. Command to run a Python file from terminal?
D) py filename C) python [Link] B) exec filename A) run [Link]
Answer: C) python [Link]
Q48. Which function prints output to screen?
D) output() C) display() B) echo() A) print()
Answer: A) print()
Q49. Which function converts any value to string?
D) chr() C) repr() B) string() A) str()
Answer: A) str()
Q50. Python is a ____ typed language.
D) Manually C) Weakly B) Statically A) Dynamically
Answer: A) Dynamically
Section 2: Strings, Lists, and Tuples (50 Questions)
Q1. What is the output of 'Python'[::-1]?
D) pYTHON C) Error B) nohtyP A) Python
Answer: B) nohtyP
Q2. Strings in Python are:
D) Fixed-length C) Constant B) Immutable A) Mutable
Answer: B) Immutable
Q3. Which method converts a string to uppercase?
D) toUpper() C) capitalize() B) upper() A) upcase()
Answer: B) upper()
Q4. 'hello'.find('l') returns:
D) 3 C) 2 B) 1 A) 0
Answer: C) 2
Q5. 'abc' * 3 gives:
D) 9 C) Error B) abc3 A) abcabcabc
Answer: A) abcabcabc
Q6. 'Python'.replace('P', 'J') → ?
D) Ppython C) Error B) Jython A) Python
Answer: B) Jython
Q7. 'CDAC'.lower() returns:
D) error C) Cdac B) CDAC A) cdac
Answer: A) cdac
Q8. 'hello world'.title() → ?
D) error C) HELLO WORLD B) Hello world A) Hello World
Answer: A) Hello World
Q9. 'python'.capitalize() → ?
D) error C) PYTHON B) python A) Python
Answer: A) Python
Q10. 'a,b,c'.split(',') returns:
D) Error C) {'a','b','c'} B) ['a','b','c'] A) ('a','b','c')
Answer: B) ['a','b','c']
Q11. ' '.join(['CDAC', 'PG', 'DBDA']) → ?
D) 'CDAC,PG,DBDA' C) Error B) ['CDAC PG DBDA'] A) 'CDAC PG DBDA'
Answer: A) 'CDAC PG DBDA'
Q12. 'hello'.count('l') → ?
D) 4 C) 3 B) 2 A) 1
Answer: B) 2
Q13. 'abcd'.index('b') → ?
D) Error C) 2 B) 1 A) 0
Answer: B) 1
Q14. 'CDAC'.startswith('C') → ?
D) None C) Error B) False A) True
Answer: A) True
Q15. '123'.isdigit() → ?
D) 123 C) Error B) False A) True
Answer: A) True
Lists
Q16. Which of these is a valid list?
D) C) [1,2,3] B) {1,2,3} A) (1,2,3) <1,2,3>
Answer: C) [1,2,3]
Q17. Lists in Python are:
D) Read-only C) Fixed B) Immutable A) Mutable
Answer: A) Mutable
Q18. What is the output of len([1,[2,3],4])?
D) Error C) 4 B) 3 A) 2
Answer: B) 3
Q19. list(range(2,10,2)) gives:
D) [2,8] C) [2,6,10] B) [2,4,6,8] A) [2,4,6,8,10]
Answer: B) [2,4,6,8]
Q20. [1,2,3]+[4,5] → ?
D) Error C) [1,2,3][4,5] B) [5,7,8] A) [1,2,3,4,5]
Answer: A) [1,2,3,4,5]
Q21. [3,1,2].sort() modifies list to:
D) Error C) [2,3,1] B) [1,2,3] A) [3,1,2]
Answer: B) [1,2,3]
Q22. sorted([3,1,2]) returns:
D) None C) (1,2,3) B) [1,2,3] A) [3,1,2]
Answer: B) [1,2,3]
Q23. [1,2,3].append(4) → ?
D) 4 C) Error B) None A) [1,2,3,4]
Answer: B) None (it modifies in place)
Q24. [1,2,3].extend([4,5]) → ?
D) None C) Error B) [[1,2,3],[4,5]] A) [1,2,3,4,5]
Answer: A) [1,2,3,4,5]
Q25. a=[1,2,3]; [Link](1,100); print(a)
D) Error C) [1,2,100,3] B) [100,1,2,3] A) [1,100,2,3]
Answer: A) [1,100,2,3]
Q26. a=[1,2,3]; [Link]() → ?
D) None C) 3 B) 2 A) 1
Answer: C) 3
Q27. a=[1,2,3]; [Link](2) → ?
D) Error C) [1,2,3] B) [2,3] A) [1,3]
Answer: A) [1,3]
Q28. min([3,1,4]) → ?
D) Error C) 4 B) 3 A) 1
Answer: A) 1
Q29. max([3,1,4]) → ?
D) Error C) 4 B) 3 A) 1
Answer: C) 4
Q30. [1,2]*3 → ?
D) Error C) [3,6] B) [1,2,1,2,1,2] A) [1,2,3]
Answer: B) [1,2,1,2,1,2]
Tuples
Q31. Tuples are written using:
D) C) () B) {} A) [] <>
Answer: C) ()
Q32. Tuples are:
D) None C) Both B) Immutable A) Mutable
Answer: B) Immutable
Q33. t=(1,2,3); print(t[1]) → ?
D) Error C) 3 B) 2 A) 1
Answer: B) 2
Q34. t=(1,2,3); t[1]=5 → ?
D) None C) (5,2,3) B) Error A) (1,5,3)
Answer: B) Error
Q35. tuple([1,2,3]) → ?
D) {1,2,3} C) Error B) [1,2,3] A) (1,2,3)
Answer: A) (1,2,3)
Q36. len((1,2,3,4)) → ?
D) Error C) 5 B) 4 A) 3
Answer: B) 4
Q37. (10,)*3 → ?
D) Error C) [10,10,10] B) (30,) A) (10,10,10)
Answer: A) (10,10,10)
Q38. max((1,5,3)) → ?
D) None C) 5 B) 3 A) 1
Answer: C) 5
Q39. (1,2)+(3,4) → ?
D) Error C) [1,2,3,4] B) (1,2)(3,4) A) (1,2,3,4)
Answer: A) (1,2,3,4)
Q40. min((2,4,6,1)) → ?
D) 6 C) 4 B) 2 A) 1
Answer: A) 1
Q41. a,b=(10,20) → values of a,b ?
D) 20,10 C) Error B) (10,20) A) 10,20
Answer: A) 10,20
Q42. ('a','b','c').index('b') → ?
D) Error C) 2 B) 1 A) 0
Answer: B) 1
Q43. ('a','b','c').count('a') → ?
D) Error C) 2 B) 1 A) 0
Answer: B) 1
Q44. Which function converts list to tuple?
D) dict() C) set() B) list() A) tuple()
Answer: A) tuple()
Q45. t1=(1,2); t2=(3,4); print(t1*2+t2) → ?
D) [1,2,3,4] C) Error B) (1,2,3,4) A) (1,2,1,2,3,4)
Answer: A) (1,2,1,2,3,4)
Q46. Tuples can contain lists?
D) Only strings C) Only numbers B) No A) Yes
Answer: A) Yes
Q47. (1,) is a:
D) Error C) list B) tuple A) int
Answer: B) tuple
Q48. () represents:
D) Empty list C) Error B) None A) Empty tuple
Answer: A) Empty tuple
Q49. Tuple unpacking allows:
D) None C) Reversal B) Looping only A) Assigning tuple elements to variables
Answer: A) Assigning tuple elements to variables
Q50. Tuples are faster than lists because:
D) None C) Both A and B B) Immutable A) Fixed size
Answer: C) Both A and B
Section 3: Dictionaries & Sets (50 Questions)
Q1. Which of the following creates a dictionary?
D) ('a',1) C) {'a':1,'b':2} B) ['a',1,'b',2] A) {1,2,3}
Answer: C) {'a':1,'b':2}
Q2. Keys in a Python dictionary must be:
D) Duplicates C) Both B) Immutable A) Mutable
Answer: B) Immutable
Q3. d={'a':1,'b':2}; print(d['a']) → ?
D) None C) Error B) a A) 1
Answer: A) 1
Q4. Accessing a non-existent key in a dictionary raises:
D) IndexError C) TypeError B) KeyError A) ValueError
Answer: B) KeyError
Q5. d={'a':1,'b':2}; print([Link]('c')) → ?
D) c C) Error B) None A) 0
Answer: B) None
Q6. d={'x':10}; d['y']=20 → result?
D) Nothing happens C) Deletes 'x' B) Error A) Adds new key 'y'
Answer: A) Adds new key 'y'
Q7. To get all keys from dictionary d, use:
D) keys(d) C) [Link]() B) [Link]() A) [Link]()
Answer: A) [Link]()
Q8. To get all values from dictionary d:
D) [Link]() C) [Link]() B) [Link]() A) [Link]()
Answer: B) [Link]()
Q9. d={'a':1,'b':2}; print(list([Link]())) → ?
D) Error C) [1,2] B) ['a','b'] A) [('a',1),('b',2)]
Answer: A) [('a',1),('b',2)]
Q10. len({'a':1,'b':2}) → ?
D) Error C) 3 B) 2 A) 1
Answer: B) 2
Q11. Which deletes an entry from dictionary?
D) [Link]('key') C) remove(d['key']) B) [Link]('key') A) del d['key']
Answer: A) del d['key']
Q12. Which method removes all elements?
D) [Link]() C) del d() B) [Link]() A) [Link]()
Answer: B) [Link]()
Q13. [Link]('x', 0) does what?
D) Deletes all C) Error B) Always returns 0 A) Removes ‘x’ or returns 0 if not found
Answer: A) Removes ‘x’ or returns 0 if not found
Q14. [Link](['a','b'],0) → ?
D) None C) Error B) ['a':0,'b':0] A) {'a':0,'b':0}
Answer: A) {'a':0,'b':0}
Q15. Can lists be dictionary keys?
D) Only with hash() C) Only if empty B) No A) Yes
Answer: B) No
Q16. Which method updates a dictionary?
D) modify() C) extend() B) update() A) append()
Answer: B) update()
Q17. d1={'a':1}; d2={'b':2}; [Link](d2) → d1?
D) Error C) {'b':2} B) {'a':1,'b':2} A) {'a':1}
Answer: B) {'a':1,'b':2}
Q18. 'a' in {'a':10} → ?
D) None C) Error B) False A) True
Answer: A) True
Q19. '10' in {'a':10} → ?
D) None C) Error B) False A) True
Answer: B) False
Q20. dict([(1,'a'),(2,'b')]) → ?
D) (1:'a',2:'b') C) Error B) [1:'a',2:'b'] A) {1:'a',2:'b'}
Answer: A) {1:'a',2:'b'}
Sets
Q21. How to create an empty set?
D) () C) [] B) set() A) {}
Answer: B) set()
Q22. {1,2,3,2,1} → ?
D) Error C) [1,2,3] B) {1,2,3,2,1} A) {1,2,3}
Answer: A) {1,2,3}
Q23. Sets are:
D) Immutable C) Indexed B) Unordered A) Ordered
Answer: B) Unordered
Q24. Sets allow duplicate elements?
D) Only strings C) Only numbers B) No A) Yes
Answer: B) No
Q25. Sets can contain lists?
D) Only empty lists C) Sometimes B) No A) Yes
Answer: B) No
Q26. len({1,2,2,3}) → ?
D) Error C) 2 B) 3 A) 4
Answer: B) 3
Q27. {1,2,3}.add(4) → ?
D) None C) Error B) {4,1,2,3} A) {1,2,3,4}
Answer: A) {1,2,3,4}
Q28. {1,2,3}.remove(2) → ?
D) None C) Error B) {1,2,3} A) {1,3}
Answer: A) {1,3}
Q29. {1,2,3}.discard(5) → ?
D) Adds 5 C) Removes 5 B) No error A) Error
Answer: B) No error
Q30. {1,2,3}.clear() → ?
D) {1,2,3} C) Error B) None A) {}
Answer: A) {}
Q31. {1,2,3}|{3,4} → ?
D) None C) Error B) {3} A) {1,2,3,4}
Answer: A) {1,2,3,4}
Q32. {1,2,3}&{2,3,4} → ?
D) {} C) {1,2,3,4} B) {1,4} A) {2,3}
Answer: A) {2,3}
Q33. {1,2,3}-{2} → ?
D) {} C) {1,2} B) {2,3} A) {1,3}
Answer: A) {1,3}
Q34. {1,2,3}^{3,4} → ?
D) Error C) {1,3,4} B) {3,4} A) {1,2,4}
Answer: A) {1,2,4}
Q35. set('CDAC') → ?
D) Error C) {'C','D','A'} (unordered) B) {'A','C','D'} A) {'C','D','A'}
Answer: C) {'C','D','A'} (unordered)
Q36. 'a' in {'a','b','c'} → ?
D) None C) Error B) False A) True
Answer: A) True
Q37. {1,2}.issubset({1,2,3}) → ?
D) None C) Error B) False A) True
Answer: A) True
Q38. {1,2,3}.issuperset({2,3}) → ?
D) None C) Error B) False A) True
Answer: A) True
Q39. {1,2}.isdisjoint({3,4}) → ?
D) None C) Error B) False A) True
Answer: A) True
Q40. {1,2}.union({3,4}) → ?
D) {} C) {1,2} B) {3,4} A) {1,2,3,4}
Answer: A) {1,2,3,4}
Q41. frozenset({1,2,3}) → ?
D) Frozen dict C) Error B) Mutable set A) Immutable set
Answer: A) Immutable set
Q42. Can a frozenset be a key in a dictionary?
D) Only if empty C) Sometimes B) No A) Yes
Answer: A) Yes
Q43. type(set()) → ?
D) tuple C) dict B) set A) list
Answer: B) set
Q44. len(set([1,2,3,3,2])) → ?
D) Error C) 2 B) 3 A) 5
Answer: B) 3
Q45. Sets support indexing?
D) Only for strings C) Only with slicing B) No A) Yes
Answer: B) No
Q46. set([1,2,3])=={1,2,3} → ?
D) None C) Error B) False A) True
Answer: A) True
Q47. {1,2,3}.add(3) changes the set?
D) Error C) Removes 3 B) Yes A) No
Answer: A) No
Q48. {1,2}.intersection({2,3}) → ?
D) Error C) {} B) {1,2,3} A) {2}
Answer: A) {2}
Q49. {1,2}.difference({2,3}) → ?
D) Error C) {} B) {2} A) {1}
Answer: A) {1}
Q50. {1,2}.symmetric_difference({2,3}) → ?
D) {} C) {2} B) {1,2,3} A) {1,3}
Answer: A) {1,3}
Section 4: Conditional Statements & Loops (50 Questions)
Q1. What is the correct syntax of an if statement in Python?
A) if x > B) if (x y then: > C) if x y): > D) if x y: > y then
Answer: C) if x > y:
Q2. Which keyword is used to execute code when the if condition is false?
D) except C) else B) elif A) otherwise
Answer: C) else
Q3. The elif keyword is short for:
D) none of these C) else condition B) else then A) else if
Answer: A) else if
Q4. if 5 > 2: print("Yes") prints:
D) Nothing C) Error B) No A) Yes
Answer: A) Yes
Q5. Which of the following is invalid?
D) if not a: C) if a=b: B) if (a==b): A) if True:
Answer: C) if a=b:
Q6. Which operator is used for logical AND?
A) &&C) B) and &D) +
Answer: B) and
Q7. Which operator is used for logical OR?
D) + C) | B) or A) ||
Answer: B) or
Q8. The expression not (True and False) evaluates to:
D) Error C) None B) False A) True
Answer: A) True
Q9. Which keyword is used to skip the current iteration of a loop?
D) skip C) continue B) pass A) stop
Answer: C) continue
Q10. Which keyword is used to exit a loop entirely?
D) pass C) exit B) break A) stop
Answer: B) break
Q11. What does pass statement do?
D) Raises exception C) Stops loop B) Does nothing A) Skips code temporarily
Answer: B) Does nothing
Q12. The syntax of a while loop is:
D) while: condition C) while condition do: B) while condition A) while (condition):
Answer: A) while (condition):
Q13. A while loop must include:
B) condition A) condition only & D) both B C) initialization, condition, update update & C
Answer: D) both B & C
Q14. A for loop in Python iterates over:
D) both B C) iterable objects B) sequence A) range only & C
Answer: D) both B & C
Q15. for i in range(3): print(i) prints:
D) Error C) 0 1 2 3 B) 0 1 2 A) 1 2 3
Answer: B) 0 1 2
Q16. range(5) generates:
D) 5 numbers starting from 1 C) 0–5 B) 1 2 3 4 5 A) 0 1 2 3 4
Answer: A) 0 1 2 3 4
Q17. range(2,10,2) → ?
D) 0 2 4 6 8 C) 2 3 4 5 6 7 8 9 10 B) 2 4 6 8 A) 2 4 6 8 10
Answer: B) 2 4 6 8
Q18. What happens if condition in while loop is never false?
D) Program stops C) Loop runs once B) Infinite loop A) Error
Answer: B) Infinite loop
Q19. Can a for loop have an else part?
D) Only in while C) Only in functions B) No A) Yes
Answer: A) Yes
Q20. The else part of a loop executes when:
D) always C) continue executes B) break statement executes A) Loop finishes normally
Answer: A) Loop finishes normally
Q21. for i in range(3): print(i, end=' ') prints:
D) Error C) 0,1,2 B) 012 A) 0 1 2
Answer: B) 012
Q22. sum = 0; for i in range(5): sum += i; print(sum) → ?
D) 5 C) 0 B) 15 A) 10
Answer: A) 10
Q23. Which statement causes immediate exit from loop?
D) exit C) continue B) break A) pass
Answer: B) break
Q24. for i in range(5): if i==3: break — how many times loop runs?
D) 2 C) 5 B) 4 A) 3
Answer: B) 4 (i = 0,1,2,3 → breaks at 3)
Q25. for i in range(3): pass → ?
D) Exits loop C) Skips 3 B) Error A) Does nothing
Answer: A) Does nothing
Q26. while False: block runs how many times?
D) Until break C) Infinite B) Once A) Never
Answer: A) Never
Q27. Nested loops mean:
D) None C) Infinite loop B) Two separate loops A) One loop inside another
Answer: A) One loop inside another
Q28. for i in range(2): for j in range(2): print(i,j) → prints how many pairs?
D) 5 C) 4 B) 3 A) 2
Answer: C) 4
Q29. Which statement skips rest of code in current loop iteration?
D) break C) continue B) pass A) skip
Answer: C) continue
Q30. for i in range(3): if i==1: continue; print(i) → ?
D) 0 1 C) 1 2 B) 0 1 2 A) 0 2
Answer: A) 0 2
Q31. A break inside nested loop exits:
D) Program C) None B) Only inner loop A) All loops
Answer: B) Only inner loop
Q32. for i in range(5): print(i); else: print("Done") → ?
D) Infinite loop C) Error B) Only Done A) Prints 0–4 then Done
Answer: A) Prints 0–4 then Done
Q33. The else part of a loop does not execute when:
D) None C) Loop has pass B) Loop ends normally A) Loop has break
Answer: A) Loop has break
Q34. x = 10; while x > 0: x -= 3; print(x) last printed value?
D) 10 C) 0 B) -2 A) 1
Answer: B) -2
Q35. for i in "CDAC": print(i) prints:
D) CDAC4 C) Error B) Entire word once A) Each letter
Answer: A) Each letter
Q36. How to iterate list [1,2,3] with index?
D) both B and C C) for index in enumerate(list): B) for i in range(len(list)): A) for i in list:
Answer: D) both B and C
Q37. What is output of sum(range(4))?
D) 3 C) 10 B) 6 A) 4
Answer: B) 6
Q38. In a loop, break skips to:
D) Exit loop entirely C) Next iteration B) End of loop A) Start
Answer: D) Exit loop entirely
Q39. Which is valid conditional expression syntax?
D) x when cond else y C) cond ? x : y B) if cond ? x : y A) x if cond else y
Answer: A) x if cond else y
Q40. x=5; print("Even" if x%2==0 else "Odd") prints:
D) None C) Error B) Odd A) Even
Answer: B) Odd
Q41. What is output of for i in range(1,6,2): print(i)?
D) 1 4 C) 2 4 6 B) 1 3 5 A) 1 2 3 4 5
Answer: B) 1 3 5
Q42. for i in range(5,0,-1): print(i) prints:
D) Error C) 0 1 2 3 4 B) 1 2 3 4 5 A) 5 4 3 2 1
Answer: A) 5 4 3 2 1
Q43. for i in range(2): for j in range(3): print(i+j) total prints?
D) 2 C) 6 B) 5 A) 3
Answer: C) 6
Q44. x=0; while x<3: print(x); x+=1 → ?
D) Infinite C) 0 1 2 3 B) 1 2 3 A) 0 1 2
Answer: A) 0 1 2
Q45. Infinite loop example?
D) while False: C) if True: B) for i in range(10): A) while True:
Answer: A) while True:
Q46. for i in range(1,10,3): print(i) → ?
D) 1 2 3 C) 1 4 7 10 B) 1 3 5 7 9 A) 1 4 7
Answer: A) 1 4 7
Q47. When continue is used in a while loop:
D) Restarts from 0 C) Exits program B) Stops loop A) Skips remaining code in current
iteration
Answer: A) Skips remaining code in current iteration
Q48. Which is NOT a loop control statement?
D) stop C) pass B) continue A) break
Answer: D) stop
Q49. The range() function can take:
D) All above C) 3 args B) 2 args A) 1 arg
Answer: D) All above
Q50. for i in range(3): print(i*i) prints:
D) 0 1 2 C) 1 2 3 B) 0 1 4 A) 1 4 9
Answer: B) 0 1 4
Section 5: Functions & Modules (50 Questions)
Q1. Which keyword is used to define a function in Python?
D) function C) define B) def A) func
Answer: B) def
Q2. Which statement is used to return a value from a function?
D) output C) yield B) return A) send
Answer: B) return
Q3. Functions in Python are defined using:
B) A) Curly braces def D) None C) Both keyword
Answer: B) def keyword
Q4. What is the output of:
def f(): return 5
print(f())
D) Error C) None B) 5 A) f
Answer: B) 5
Q5. If a function doesn’t have a return statement, it returns:
D) Error C) None B) Null A) 0
Answer: C) None
Q6. Parameters passed to a function are called:
D) Constants C) Attributes B) Identifiers A) Arguments
Answer: A) Arguments
Q7. The term “parameter” refers to:
D) None C) Function name B) Actual value passed A) Variable inside function definition
Answer: A) Variable inside function definition
Q8. “Arguments” refer to:
D) None C) Both B) Values passed while calling A) Variables inside function
Answer: B) Values passed while calling
Q9. Default arguments are used when:
D) Function not defined C) Function returns None B) Value is passed A) No value is
passed
Answer: A) No value is passed
Q10. Example of default argument:
def greet(name="Guest"):
print("Hello", name)
What will greet() print?
D) None C) Hello Guest B) Hello A) Error
Answer: C) Hello Guest
Q11. Which is correct syntax to call a function named sum()?
D) function sum() C) sum() B) sum A) call sum()
Answer: C) sum()
Q12. Functions help in:
D) All above C) Modular programming B) Readability A) Code reuse
Answer: D) All above
Q13. What is the output?
def f(x): return x+2
print(f(3))
D) 6 C) Error B) 5 A) 3
Answer: B) 5
Q14. Can a function call itself?
D) Only once C) Only in loops B) No A) Yes
Answer: A) Yes (Recursion)
Q15. Function inside another function is called:
D) Lambda C) Internal function B) Local function A) Nested function
Answer: A) Nested function
Q16. Which keyword defines an anonymous function?
D) anon C) lambda B) func A) def
Answer: C) lambda
Q17. lambda x: x+5 is equivalent to:
D) None C) f(x)=x+5 B) x=x+5 A) def f(x): return x+5
Answer: A) def f(x): return x+5
Q18. What will this print?
x = lambda a,b: a*b
print(x(2,3))
D) 23 C) Error B) 5 A) 6
Answer: A) 6
Q19. Lambda functions are also called:
D) Named functions C) Both B) Anonymous functions A) Inline functions
Answer: C) Both
Q20. Lambda functions can have how many expressions?
D) Unlimited C) Many B) Two A) One
Answer: A) One
Q21. Which of the following is true about global variables?
D) Temporary C) Local only B) Accessible everywhere A) Declared inside a function
Answer: B) Accessible everywhere
Q22. Keyword used to declare a global variable inside a function:
D) var C) extern B) public A) global
Answer: A) global
Q23. What happens if two functions have same name?
D) Random C) Both run B) Last one overrides A) Error
Answer: B) Last one overrides
Q24. The return statement exits function:
D) Never C) After printing B) After loop ends A) Immediately
Answer: A) Immediately
Q25. Can a function return multiple values?
D) Only in loops C) Only one B) No A) Yes
Answer: A) Yes (as tuple)
Q26. Example of returning multiple values:
def data():
return 1,2,3
Type of returned value?
D) Set C) Dict B) Tuple A) List
Answer: B) Tuple
Q27. Which statement is correct?
D) All C) Function returns 0 B) Function can return None A) Function must always return
value
Answer: B) Function can return None
Q28. Functions that modify external variables without returning are called:
D) None C) Global modifiers B) Void functions A) Non-returning functions
Answer: B) Void functions
Q29. In Python, functions are:
D) None C) Types B) Keywords A) Objects
Answer: A) Objects
Q30. Function arguments can be:
D) All above C) Keyword B) Default A) Required
Answer: D) All above
Q31. Example of keyword argument:
def info(name, age): print(name, age)
info(age=21, name="Amit")
Output?
D) None C) 21 Amit B) Amit 21 A) Error
Answer: B) Amit 21
Q32. What does *args do?
D) Both A C) Creates tuple B) Passes only integers A) Accepts variable number of
arguments & C
Answer: D) Both A & C
Q33. What does **kwargs do?
C) Both A B) Creates dictionary A) Passes keyword args & D) None B
Answer: C) Both A & B
Q34. What will this print?
def f(*args):
print(args)
f(1,2,3)
D) None C) [1,2,3] B) (1,2,3) A) Error
Answer: B) (1,2,3)
Q35. Which is used to import a module?
D) require C) use B) import A) include
Answer: B) import
Q36. Example of module import:
import math
print([Link](9))
Output?
D) sqrt(9) C) Error B) 3 A) 3.0
Answer: A) 3.0
Q37. Import only specific function from module:
D) both A C) import sqrt from math B) import [Link] A) from math import sqrt & B
Answer: A) from math import sqrt
Q38. Rename module while importing:
C) import math - B) import math rename m A) import math as m> D) None m
Answer: A) import math as m
Q39. dir(math) gives:
D) None C) Both B) List of attributes A) List of functions
Answer: C) Both
Q40. Which module provides random number generation?
D) numbers C) randint B) math A) random
Answer: A) random
Q41. import random; print([Link](1,3)) prints:
D) Any of these C) 3 B) 2 A) 1
Answer: D) Any of these
Q42. What is a module?
D) Variable C) A class B) A loop A) File containing functions
Answer: A) File containing functions
Q43. A collection of related modules is called:
D) A or C C) Library B) Folder A) Package
Answer: D) A or C
Q44. How to install external Python packages?
D) setup install C) pkg install B) pip install package_name A) using [Link]
Answer: B) pip install package_name
Q45. Which built-in module deals with date & time?
D) All above C) calendar B) time A) datetime
Answer: D) All above
Q46. What does __name__ == "__main__" mean?
D) None C) Used for loops B) Always true A) Code runs only if script is main
Answer: A) Code runs only if script is main
Q47. Which module is used for file system operations?
D) shutil C) io B) os A) sys
Answer: B) os
Q48. Which module provides system-specific parameters?
D) time C) subprocess B) os A) sys
Answer: A) sys
Q49. help(math) gives:
D) None C) Error B) Only functions list A) Documentation of math module
Answer: A) Documentation of math module
Q50. from random import * means:
D) Error C) Import only randint B) Import none A) Import all from random
Answer: A) Import all from random