Conceptual Actual Emended Exam Questions
With Reviewed 100% Correct Detailed Answers
Guaranteed Pass!!Current Update
Q1: What is garbage collection in Python, and why is it important?
A1: Garbage collection is the automatic process of deleting unused objects to
free up memory. It prevents memory leaks and optimizes performance.
Q2: Explain how Python's garbage collector determines which objects to delete.
A2: Python uses reference counting (deletes objects with zero references) and
a cycle detector (handles circular references).
Q3: True or False? Manually deleting objects (e.g., using del) immediately frees
up memory in Python.
A3: False. del removes the reference, but memory is freed only when the
garbage collector runs.
Q4: What is name binding in Python? Provide an example.
A4: Binding associates a variable name with an object. Example:
python
x = 10 # Binds name 'x' to the integer object 10.
Q5: What happens when you assign a = 10 and then b = a? Does
changing b affect a? Explain.
A5: Both a and b refer to the same object (10). Since integers are immutable,
changing b (e.g., b = 20) rebinds it to a new object, leaving a unchanged.
Q6: What is the difference between x = 5 and x == 5 in terms of name binding?
A6: x = 5 binds the name x to 5. x == 5 checks if x’s value is 5 (no binding occurs).
Q7: What are the three fundamental properties of every Python object?
A7: Value, type, and identity (memory address).
,Q8: How can you check the identity of an object in Python? Provide a code
example.
A8: Use id(). Example:
python
x = 10
print(id(x)) # Outputs a unique integer (e.g., 140736372135168).
Q9: If two variables refer to the same object, what will id(var1) ==
id(var2) return?
A9: True (they share the same memory address).
Q10: What is an immutable object? Give two examples.
A10: An object that cannot be modified after creation. Examples: int, str, tuple.
Q11: Explain why modifying an immutable object inside a function creates a
new object.
A11: Immutable objects cannot be changed in-place. Any "modification" (e.g., x
+= 1) rebinds the name to a new object in the function’s local scope.
Q12: Predict the output:
python
x = (1, 2, 3)
x[0] = 10 # Attempt to modify tuple.
print(x)
A12: TypeError (tuples are immutable).
Q13: What is the approximate maximum value a floating-point number can hold
in Python?
A13: ~1.8 × 10³⁰⁸.
Q14: Convert 5.2e3 to standard decimal notation.
A14: 5200.0.
,Q15: What will 1.8e308 * 10 result in? Explain.
A15: OverflowError or inf (exceeds floating-point limit).
Q16: Write Python code to compute the absolute value of -7.5.
A16:
python
print(abs(-7.5)) # Output: 7.5
Q17: How do you calculate the square root of 25 in Python? Show the necessary
import.
A17:
python
import math
print(math.sqrt(25)) # Output: 5.0
Q18: What error occurs if you try math.sqrt(-1)? How could you handle it?
A18: ValueError. Handle with:
python
import math
try:
math.sqrt(-1)
except ValueError:
print("Cannot sqrt negative numbers!")
Q19: Write code to ask the user for an integer input and handle invalid entries.
A19:
python
try:
num = int(input("Enter an integer: "))
, except ValueError:
print("Invalid input!")
Q20: What is the default data type of input() in Python? How do you convert it
to a float?
A20: str. Convert with float(input()).
Q21: What does int("5.5") raise? How would you safely convert "5.5" to an
integer?
A21: Raises ValueError. Safely convert with:
python
float_num = float("5.5")
int_num = int(float_num) # Truncates to 5.
Q22: What is a string literal? Give two ways to define one.
A22: A string value specified in code. Examples: 'hello', "world", '''multiline'''.
Q23: What is the difference between 'hello' and '''hello''' in Python?
A23: '''hello''' allows multiline strings (e.g., '''Line 1\nLine 2''').
Q24: Predict the output:
python
s = "Python"
print(s[0] = 'J') # Attempt to modify string.
A24: TypeError (strings are immutable).
Q25: Why does a = 256; b = 256; a is b return True, but a = 257; b = 257; a is
b may return False?
A25: Python caches small integers (e.g., -5 to 256), so 256 is the same object.
Larger integers (e.g., 257) may be separate objects.