EXAM AND PRACTICE QUESTIONS AND SOLution
Section 1: Basic Syntax & Data Types
Q1. What is the output of print(type(10/2))?
• A) <class 'int'>
• B) <class 'float'>
• C) <class 'double'>
• D) <class 'str'>
Answer: B. <class 'float'>
Rationale: In Python, the / operator performs true division and always returns a
float, even when the numbers divide evenly (e.g., 10/2 = 5.0).
Q2. Which of the following data types is immutable?
• A) list
• B) dict
• C) set
• D) tuple
Answer: D. tuple
Rationale: A tuple cannot be changed after creation (immutable). Lists,
dictionaries, and sets are mutable and can be modified after creation.
Q3. What will the following code print?
python
x = "Hello"
print(x[1])
• A) H
• B) e
, • C) l
• D) o
Answer: B. e
Rationale: Strings are zero-indexed. Index 0 → 'H', index 1 → 'e'.
Q4. What is the output of print(2 ** 3)?
• A) 6
• B) 8
• C) 9
• D) 5
Answer: B. 8
Rationale: The ** operator is the exponentiation operator. 2 ** 3 means 2 raised
to the power of 3, which is 2 * 2 * 2 = 8.
Q5. Which loop is best used when the number of iterations is unknown?
• A) for loop
• B) while loop
• C) nested loop
• D) for-each loop
Answer: B. while loop
Rationale: A while loop runs until a condition becomes False, making it ideal
when the number of iterations is not known in advance.
Q6. What does the break statement do in a loop?
• A) Skips the current iteration
• B) Exits the loop completely
• C) Restarts the loop from the beginning
• D) Pauses the loop temporarily
,Answer: B. Exits the loop completely
Rationale: The break statement immediately terminates the nearest enclosing
loop. Execution continues with the first statement after the loop.
Q7. What is the output of print("Python"[::-1])?
• A) Python
• B) nohtyP
• C) nohtyp
• D) Error
Answer: B. nohtyP
Rationale: [::-1] is a slicing syntax that reverses the string. It starts from the end
and moves backward, producing "nohtyP".
Q8. Which keyword is used to define a function in Python?
• A) function
• B) def
• C) define
• D) func
Answer: B. def
Rationale: Functions are defined using the def keyword, followed by the function
name, parentheses, and a colon.
Q9. Which data structure stores key-value pairs?
• A) list
• B) tuple
• C) dictionary
• D) array
Answer: C. dictionary
Rationale: Dictionaries use key: value mapping. Each key is unique and is used to
access its associated value.
, Q10. What is the value of 10 % 3?
• A) 1
• B) 2
• C) 3
• D) 0
Answer: A. 1
Rationale: The % operator is the modulo operator, which returns the remainder
of division. 10 ÷ 3 = 3 with a remainder of 1.
Q11. Which of the following is a valid Python variable name?
• A) 2variable
• B) variable-2
• C) variable_2
• D) variable 2
Answer: C. variable_2
Rationale: Variable names cannot start with a number, cannot contain hyphens,
and cannot contain spaces. Underscores are allowed.
Q12. What does the append() method do when called on a list?
• A) Removes an element from the list
• B) Adds an element to the end of the list
• C) Inserts an element at a specific index
• D) Sorts the list
Answer: B. Adds an element to the end of the list
Rationale: append() adds a single element to the end of a list, increasing the list's
length by one.
Q13. What is the output of bool([])?
• A) True