– 200 Practice Questions with Answers and
Rationales (Latest Update)
Introduction
This comprehensive set of 200 Python Programming Final Exam Questions is designed to test and
reinforce your understanding of Python fundamentals, core concepts, and best practices. It covers
a wide range of topics typically included in an introductory to intermediate Python course,
including:
Data types and type conversion
Variables, operators, and expressions
Control flow (conditionals, loops, break, continue, else in loops)
Data structures (lists, tuples, dictionaries, sets, strings)
Functions, lambdas, and scope
Exception handling (try/except/finally)
File I/O and context managers
Modules and imports
Object-oriented programming basics (class, __init__, methods)
Built-in functions (len(), range(), zip(), map(), filter(), etc.)
Iterators, generators, and comprehensions
Advanced operators (floor division, modulo, exponentiation, bitwise)
Special methods, decorators, and lambda functions
Common pitfalls (floating-point precision, mutability, identity vs. equality)
,1. What is the output of print(type())?
A) <class 'int'>
B) <class 'float'>
C) <class 'complex'>
D) <class 'decimal'>
Answer: B
*Rationale: In Python 3, the / operator always returns a float, even if the division is exact.*
2. Which of the following is a valid variable name in Python?
A) 2var
B) var-name
C) _var
D) var name
Answer: C
Rationale: Variable names cannot start with a digit, contain hyphens or spaces. Underscore
is allowed.
3. What does the len() function return for a string?
A) Number of words
B) Number of characters including spaces
C) Number of characters excluding spaces
D) Number of unique characters
Answer: B
Rationale: len() returns the total number of characters in the string, spaces and punctuation
included.
4. What is the result of bool([])?
A) True
B) False
C) None
D) Error
Answer: B
Rationale: Empty sequences (list, tuple, string, etc.) evaluate to False in a boolean context.
5. Which statement is used to terminate a loop prematurely?
A) stop
B) exit
C) break
D) return
Answer: C
Rationale: The break statement exits the innermost loop. return exits a function, not a loop.
,6. What is the output of print("Hello" * 3)?
A) HelloHelloHello
B) Hello Hello Hello
C) Hello*3
D) Error
Answer: A
Rationale: The * operator repeats a string the specified number of times, concatenating the
copies.
7. How do you create a dictionary in Python?
A) {}
B) []
C) ()
D) <>
Answer: A
Rationale: Curly braces define a dictionary. Square brackets for list, parentheses for tuple.
8. What is the output of print(3 == 3.0)?
A) True
B) False
C) Error
D) None
Answer: A
Rationale: Python performs type coercion in comparisons; integer 3 equals float 3.0.
9. Which function reads a line from the user as a string?
A) read()
B) scan()
C) input()
D) get()
Answer: C
Rationale: input() reads a line from standard input and returns it as a string.
10. What is the correct way to write a single-line comment in Python?
A) /* comment */
B) # comment
C) // comment
D) <!-- comment -->
Answer: B
Rationale: The hash character # starts a comment that extends to the end of the line.
11. What is the output of print(10 // 3)?
A) 3.333
B) 3
C) 3.0
, D) 4
Answer: B
Rationale: // is floor division, which returns the integer quotient (discarding remainder).
12. Which method adds an element to the end of a list?
A) insert()
B) add()
C) append()
D) extend()
Answer: C
Rationale: append() adds a single element to the end of the list. extend() adds multiple
elements.
13. What does the range(5) function generate?
A) [1,2,3,4,5]
B) [0,1,2,3,4]
C) [0,1,2,3,4,5]
D) [1,2,3,4]
Answer: B
*Rationale: range(stop) starts at 0 and stops before stop, so it yields 0 to stop-1.*
14. Which keyword is used to define a function?
A) def
B) function
C) define
D) func
Answer: A
Rationale: The def keyword is used to define a user-defined function in Python.
15. What is the output of print(2 ** 3 ** 2)?
A) 64
B) 512
C) 12
D) 64
Answer: B
*Rationale: Exponentiation is right-associative, so 32=9, then 29=512.*
16. How can you get the number of elements in a list named mylist?
A) mylist.count()
B) len(mylist)
C) mylist.length()
D) size(mylist)
Answer: B
Rationale: The built-in len() function returns the number of items in a container.