Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
3.4k views
in Computer by (22.7k points)
How we update and delete tuples ?

1 Answer

0 votes
by (28.2k points)
selected by
 
Best answer
Updating Tuples :

Tuples are immutable which means you cannot update them or change values of tuple elements. But we are able to take portions of an existing tuples to create a new tuples as follows. Following is a simple example :

#!/user/bin/python

tup1 =(12,34.56);

tup2 = (‘abc’, ‘xyz’);

#Following action is not valid for tuples

#tup1[0] = 100;

#So lets create a new tuple as follows :

tup3 = tup1 + tup2;

print tup3;

When the above code is executed, it produces the following result :

(12,34.56, ‘abc’, ‘xyz’)

Delete Tuple Elements :

Removing individual tuple elements is not possible. There is, of course, nothing

wrong with putting together another tuple with the undesired elements

discarded.

To explicity remove an entire tuple, just use the del statement. Following is a

simple example :

#!/user/bin/python

tup = (‘physics’, ‘chemistry’, 1997,2000);

print tup;

del tup;

print “After deleting tup:”

print tup;

This will produce following result. Note an exception raised, there is because after

del tup tuple does not exist any more :

(‘physics’, ‘chemistry’, 1997,2000)

After deleting tup :

Traceback (most recent call last) :

Fill “test.py”, line 9, in < modulo>

print tup;

Name Error : name ‘tup’ is not defined

Related questions

+1 vote
1 answer
asked Aug 31, 2018 in Computer by AnujPatel (54.7k points)
0 votes
1 answer
asked Mar 21, 2023 in Python by kvdevika (178k points)
0 votes
1 answer
asked Mar 21, 2023 in Python by kvdevika (178k points)
0 votes
1 answer
0 votes
2 answers
asked Mar 21, 2023 in Python by kvdevika (178k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...