Python Programming - Variables
Exercise : Variables - General Questions
- Variables - General Questions
36.
What is the output of the following code:
my_tuple = (1, 2, 3)
my_tuple[0] = 4
print(my_tuple)
Answer: Option
Explanation:
In the given code, the tuple my_tuple
is created with the values (1, 2, 3)
. However, the subsequent attempt to modify the first element of the tuple using the assignment my_tuple[0] = 4
will result in an error.
Tuples in Python are immutable, meaning their elements cannot be modified after the tuple is created. Therefore, the code will raise a TypeError when trying to modify the tuple.
The output of the code will be:
TypeError: 'tuple' object does not support item assignment
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers