Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 79 of 102
Marks: +1, -0
Given the following Tuple
Tup= (10, 20, 30, 50)
Which of the following statements will result in an error ?
[CBSE 2023 Set 4]
Solution:  
Concept:
A tuple is immutable: once created, elements cannot be added, removed or changed. Indexing, slicing and len() only read the tuple, so they work.
Explanation:
Tup.insert(2,3) tries to add an element. A tuple has no insert() method, so Python raises
AttributeError: 'tuple' object has no attribute 'insert'
The other three statements print 10, (20,) and 4.
Answer:
Option B (Tup.insert (2,3))
© examsnet.com
Advertisements
Go to Question: