PYTHON PROGRAMMING FINAL EXAM;; quEsTIONs ANd
ANswERs wITH RATIONALEs/GRAdEd A+/2026 uPdATE/100%
cORREcT /INsTANT dOwNLOAd
SECTION 1: FUNDAMENTALS & DATA TYPES
**Question 1**
What is the output of the following code?
```python
print(type())
```
A) `<class 'int'>`
B) `<class 'float'>`
C) `<class 'complex'>`
D) `<class 'div'>`
**Answer:** B) `<class 'float'>`
**Rationale:** In Python 3, the `/` operator always performs floating-point division,
regardless of operand types. Even though 10 and 2 are integers, the result is 5.0, which
is a float. To get integer division, use `//`.
---
**Question 2**
,Which of the following is a valid variable name in Python?
A) `2variable`
B) `my-variable`
C) `_variable`
D) `my variable`
**Answer:** C) `_variable`
**Rationale:** Variable names in Python must start with a letter (a-z, A-Z) or underscore
(_) and cannot start with a number. They cannot contain spaces or hyphens. Underscore
is commonly used for "private" or temporary variables.
---
**Question 3**
What is the output of this code?
```python
x = [1, 2, 3]
y=x
y.append(4)
print(x)
```
A) `[1, 2, 3]`
B) `[1, 2, 3, 4]`
C) `[4]`
D) `None`
,**Answer:** B) `[1, 2, 3, 4]`
**Rationale:** Lists are mutable objects in Python. When `y = x` is executed, `y` becomes
a reference to the same list object as `x`, not a copy. Modifying the list through `y` also
affects `x` because both variables point to the same memory location.
---
**Question 4**
Which operator is used for exponentiation in Python?
A) `^`
B) `**`
C) `*`
D) `%%`
**Answer:** B) `**`
**Rationale:** The `**` operator performs exponentiation (power). For example, `2 ** 3`
returns `8`. The `^` operator performs bitwise XOR, not exponentiation.
---
**Question 5**
What is the result of `bool([])` in Python?
A) `True`
B) `False`
C) `None`
, D) `Error`
**Answer:** B) `False`
**Rationale:** In Python, empty sequences (lists, tuples, strings), empty dictionaries, and
the number 0 evaluate to `False` in a boolean context. Non-empty containers and non-
zero numbers evaluate to `True`. An empty list `[]` is considered falsy.
---
**Question 6**
What does the `len()` function return when called on a dictionary?
A) The number of key-value pairs
B) The number of keys only
C) The number of values only
D) The total memory size
**Answer:** A) The number of key-value pairs
**Rationale:** The `len()` function returns the number of items in a container. For a
dictionary, this is the number of key-value pairs. It does not count values separately or
measure memory usage.
---
**Question 7**
What is the output of this code?
```python
ANswERs wITH RATIONALEs/GRAdEd A+/2026 uPdATE/100%
cORREcT /INsTANT dOwNLOAd
SECTION 1: FUNDAMENTALS & DATA TYPES
**Question 1**
What is the output of the following code?
```python
print(type())
```
A) `<class 'int'>`
B) `<class 'float'>`
C) `<class 'complex'>`
D) `<class 'div'>`
**Answer:** B) `<class 'float'>`
**Rationale:** In Python 3, the `/` operator always performs floating-point division,
regardless of operand types. Even though 10 and 2 are integers, the result is 5.0, which
is a float. To get integer division, use `//`.
---
**Question 2**
,Which of the following is a valid variable name in Python?
A) `2variable`
B) `my-variable`
C) `_variable`
D) `my variable`
**Answer:** C) `_variable`
**Rationale:** Variable names in Python must start with a letter (a-z, A-Z) or underscore
(_) and cannot start with a number. They cannot contain spaces or hyphens. Underscore
is commonly used for "private" or temporary variables.
---
**Question 3**
What is the output of this code?
```python
x = [1, 2, 3]
y=x
y.append(4)
print(x)
```
A) `[1, 2, 3]`
B) `[1, 2, 3, 4]`
C) `[4]`
D) `None`
,**Answer:** B) `[1, 2, 3, 4]`
**Rationale:** Lists are mutable objects in Python. When `y = x` is executed, `y` becomes
a reference to the same list object as `x`, not a copy. Modifying the list through `y` also
affects `x` because both variables point to the same memory location.
---
**Question 4**
Which operator is used for exponentiation in Python?
A) `^`
B) `**`
C) `*`
D) `%%`
**Answer:** B) `**`
**Rationale:** The `**` operator performs exponentiation (power). For example, `2 ** 3`
returns `8`. The `^` operator performs bitwise XOR, not exponentiation.
---
**Question 5**
What is the result of `bool([])` in Python?
A) `True`
B) `False`
C) `None`
, D) `Error`
**Answer:** B) `False`
**Rationale:** In Python, empty sequences (lists, tuples, strings), empty dictionaries, and
the number 0 evaluate to `False` in a boolean context. Non-empty containers and non-
zero numbers evaluate to `True`. An empty list `[]` is considered falsy.
---
**Question 6**
What does the `len()` function return when called on a dictionary?
A) The number of key-value pairs
B) The number of keys only
C) The number of values only
D) The total memory size
**Answer:** A) The number of key-value pairs
**Rationale:** The `len()` function returns the number of items in a container. For a
dictionary, this is the number of key-value pairs. It does not count values separately or
measure memory usage.
---
**Question 7**
What is the output of this code?
```python