CBSE Class 11 Computer Science
Question 2 of 88
Tuples and Dictionary — Question 2
Back to all questions 2
Question Consider the given two statements:
Statement 1: t1 = tuple('python')
Statement 2: t1[4] = 'z'
Assertion (A): The above code will generate an error.
Reasoning (R): Tuple is immutable by nature.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Both A and R are true and R is the correct explanation of A.
Explanation
The statement t1 = tuple('python') creates a tuple t1 from the string 'python', resulting in t1 being ('p', 'y', 't', 'h', 'o', 'n'). The statement t1[4] = 'z' attempts to modify the element at index 4 of the tuple, which is not allowed because tuples are immutable in Python. Hence, it raises an error.