Q1. What will be the output?
x = [1, 2, 3]
y = x
y.append(4)
print(x)
โ Answer:
[1, 2, 3, 4]
๐ก Explanation:
"y = x" does not create a new list.
Both "x" and "y" point to the same list in memory.
So when:
y.append(4)
the original list also gets updated.
โโโโโโโโโโโโโโโ
Q2. What will be the output?
print(2**3**2)โ Answer:
512
๐ก Explanation:
Exponent operator ("**") works from RIGHT to LEFT.
So
2**3**2be(2**(3**2)= 2 ** 9
= 512
โโโโโโโโโโโโโโโ
Q3. What will be the output?
a = "5"
b = 2
print(a * b)
โ Answer:
55
๐ก Explanation:
In Python:
string * number
means repetition.
So:
"5" * 2
becomes:
"55"
โโโโโโโโโโโโโโโ
Q4. What will be the output?
def func(items=[]):
items.append(1)
return items
print(func())
print(func())
โ Answer:
[1]
[1, 1]
๐ก Explanation:
Default mutable arguments are created only once.
So the same list is reused every time the function is called.
First call:
[1]
Second call:
[1, 1]
โโโโโโโโโโโโโโโ
Q5. What will be the output?
for i in range(3):
print(i)
else:
print("Done")
โ Answer:
0
1
2
Done
๐ก Explanation:
The "else" block inside loops executes when the loop finishes normally.
Since there is no "break" statement, the loop completes successfully and then prints:
Double Tap โค๏ธ For More