Python Data Types and Variables 3 — Questions and Answers
Question 1: What is the result of `isinstance(True, int)`?
- False
- True (Correct answer)
- TypeError
- None
Correct answer: True
Since `bool` is a subclass of `int`, `isinstance(True, int)` returns `True`.
Question 2: Which Python built-in returns the memory address of an object?
- ref()
- addr()
- id() (Correct answer)
- mem()
Correct answer: id()
`id()` returns the unique integer identity (memory address) of an object.
Question 3: What happens when you assign `a = b = c = 10` in Python?
- Only `a` gets 10; the rest are undefined
- All three variables point to the same object 10 (Correct answer)
- Three separate copies of 10 are created
- SyntaxError is raised
Correct answer: All three variables point to the same object 10
Chained assignment makes all three names reference the same integer object 10.
Question 4: What is the output of `x = 10; del x; print(x)`?
- 10
- None
- 0
- NameError (Correct answer)
Correct answer: NameError
`del x` removes the name binding, so accessing `x` afterwards raises `NameError`.
Question 5: Which expression uses augmented assignment to add 5 to variable `n`?
- n =+ 5
- n += 5 (Correct answer)
- n = n + +5
- add(n, 5)
Correct answer: n += 5
`n += 5` is the augmented assignment operator that adds 5 to `n` in place.
Question 6: What does `float('inf')` represent in Python?
- A very large integer
- Positive infinity as a float (Correct answer)
- An undefined value
- It raises ValueError
Correct answer: Positive infinity as a float
`float('inf')` produces the IEEE 754 positive infinity float value.
Question 7: In Python, which of the following is a mutable data type?
- int
- tuple
- str
- list (Correct answer)
Correct answer: list
Lists are mutable — their elements can be changed after creation; int, tuple, and str are immutable.
What is the result of `isinstance(True, int)`?