Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
24
7
80
8.7K
Oz
Oz@Oz_70th·
@PythonPr I’d say error as tuples are immutables..?
English
0
0
0
345
Sixtus Agbakwuru
Sixtus Agbakwuru@SixtusAgbakwuru·
Answer: D. Error 🚫 (Specifically, an AttributeError) Why? In Python, tuples are immutable. This means their contents cannot be changed after creation. The insert() method is used to add an element to a list, which is a mutable sequence. Since Tuple is a tuple (not a list), it does not have an insert() method. Attempting to call Tuple.insert(2, 15) will raise an AttributeError because the insert attribute (method) does not exist for tuple objects.
English
2
0
11
686
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr The correct answer is D. Error. why the code fails: The Problem: Immutability In Python, tuples are immutable, meaning once they are created, they cannot be changed, added to, or modified. Because of this: Tuples do not have an .insert() method. The .insert() method belongs to
English
1
0
5
332
Jenny
Jenny@JennyTheDev·
@PythonPr D) Error Tuples are immutable in Python. They don't have an insert() method. The tricky part: The variable is named "Tuple" to confuse you, but it's still a tuple (lowercase parentheses). AttributeError: 'tuple' object has no attribute 'insert'
English
0
0
2
487
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output: D) Error Explanation: Tuples are immutable in Python. They don’t support insert() (that method exists only for lists). Tuple = (5, 10, 20) Tuple.insert(2, 15) # ❌ AttributeError
English
0
0
1
371
Evil_Hunter
Evil_Hunter@imsmartVik·
@PythonPr tuple is immutable so no changes allowed it will through error option D is correct
English
0
0
1
48
Manjunath.c
Manjunath.c@manjunath200425·
@PythonPr Tuple is unchangeable we can't add and modify the tuple soooo answers is error
English
0
0
0
115
Python Tech
Python Tech@PythonTech43716·
@PythonPr D) Error Tuple is immutable so answer is Error. If the data type list then insert is possible.
English
0
0
0
184
Terrence
Terrence@terrenceeleven·
@PythonPr D. Error Fails with an AttributeError because tuples lack the insert() method. AI .@PythonPr
English
0
0
0
96
Mohit
Mohit@mohit007_st·
@PythonPr D: Error as tuple is immutable
English
0
0
0
14
Paylaş