Questions
100 Advanced Practice Questions with Answers & Detailed Rationales
Section 1: Variables, Data Types & Type Conversion (Questions 1–25)
1. Which of the following is a valid variable name in Python?
A) 2ndPlace
B) my-variable
C) my_variable
D) class
Answer C: — my_variable
Rationale: Python variable names cannot start with a digit (eliminating
2ndPlace), cannot contain hyphens (eliminating my-variable), and cannot be
reserved keywords like `class` (eliminating class). Underscores are allowed and
commonly used, so `my_variable` is valid. ---
,2. What is the output of the following code? ```python x = 5 y = 10 print(x +
y) ```
A) 510
B) 15
C) 15
D) 5 10
Answer B: — 15
Rationale: The `+` operator performs arithmetic addition when both operands
are integers. The values 5 and 10 are added to produce 15. If the operands
were strings, `+` would concatenate them, but here they are integers, so
numeric addition occurs. ---
3. What is the output of the following code? ```python print(type()) ```
A) `<class 'int'>`
B) `<class 'float'>`
C) `<class 'double'>`
D) `<class 'str'>`
Answer B: — `<class 'float'>`
Rationale: In Python, the division operator `/` always returns a float, even if
the numbers divide evenly. Therefore, `` evaluates to `5.0`, and
`type(5.0)` returns `float`. Python does not have a separate `double` type. ---
,4. Which data type is immutable in Python?
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. ---
5. What will the following code print? ```python x = "Hello" print(x[1]) ```
A) H
B) e
C) l
D) o
Answer B: — e
Rationale: String indexing starts at 0 in Python. `x[0] = 'H'`, `x[1] = 'e'`, so the
output is `'e'`. ---
6. What is the output of the following code? ```python 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 equals 8. ---
7. What is the output of the following code? ```python x = "5" y = 2 print(x y)
```
A) 10
B) Error
C) "55"
D) 5
Answer C: — "55"
Rationale: When a string is multiplied by an integer, Python repeats
(concatenates) the string that many times. The string `"5"` is repeated 2 times,
resulting in `"55"`. This is known as string replication. ---
8. What is the output of `print(10 // 3)`?
A) 3.33