- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How we can update a Python tuple element value?
Python tuple is an immutable object. Hence any operation that tries to update it is not allowed. However, following workaround can be used.
First, convert tuple to list by built-in function list(). You can always update an item to list object assigning new value to element at certain index. Then use another built-in function tuple() to convert this list object back to tuple.
>>> T1=(10,50,20,9,40,25,60,30,1,56) >>> L1=list(T1) >>> L1[5]=100 >>> T1=tuple(L1) >>> T1 (10, 50, 20, 9, 40, 100, 60, 30, 1, 56)
Element at index 4 in original tuple has been changed from 25 to 100.
- Related Articles
- How we can update a Python list element value?
- How we can use Python Tuple within a Tuple?
- Update each element in tuple list in Python
- How can we update any value in MySQL view as we can update the values in MySQL table?
- How we can create a dictionary from a given tuple in Python?
- How can we update a record in MongoDB?
- How can we update values in a MySQL table?
- How can I append a tuple into another tuple in Python?
- How do we define tuple in Python?
- How can I subtract tuple of tuples from a tuple in Python?
- How can we update columns values on multiple rows with a single MySQL UPDATE statement?
- How do we grep a particular keyword from Python tuple?
- How can I create a non-literal python tuple?
- How I can convert a Python Tuple into Dictionary?
- How can I convert a Python tuple to string?

Advertisements