Python Code Output/Error (Class 10 Level)
1. Modify Tuple's List Element
Code:
t = (23, 56, [4, 8, 9], 34)
t[2][1] = 3
print(t)
Output:
(23, 56, [4, 3, 9], 34)
Explanation:
Tuples are immutable, but if they contain a mutable object (like a list), the contents of that object can
be changed.
2. Remove from Tuple (Error)
Code:
t = (23, 56, [4, 8, 9], 34)
[Link](t[2][1])
print(t)
Error:
AttributeError: 'tuple' object has no attribute 'remove'
Explanation:
Tuples do not support item removal. The remove() method is available only for lists.
Python Code Output/Error (Class 10 Level)
3. Update Dictionary
Code:
d = {1:2, 2:1, 3:5, 5:3}
d1 = {3:8}
[Link](d1)
print(d)
Output:
{1: 2, 2: 1, 3: 8, 5: 3}
Explanation:
[Link](d1) replaces the value of key 3 with 8.
4. Nested Print Statement
Code:
print(print("hello"))
Output:
hello
None
Explanation:
The inner print("hello") executes first and prints 'hello'. Then print() returns None, which is printed by
the outer print.