- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Python Program to Edit objects inside tuple
When it is required to edit the objects inside a tuple, simple indexing can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
Below is a demonstration for the same −
Example
my_tuple = (45, 67, [35, 66, 74], 89, 100) print("The tuple is : ") print(my_tuple) my_tuple[2][1] = 63 print("The tuple after changes is : ") print(my_tuple)
Output
The tuple is : (45, 67, [35, 66, 74], 89, 100) The tuple after changes is : (45, 67, [35, 63, 74], 89, 100)
Explanation
- A tuple of list is defined, and is displayed on the console.
- Since a tuple is immutable, but if the tuple contains a list, it can be varied.
- This is because the list is actually a mutable type.
- This can be done by accessing the index of the elements in the list.
- It is then displayed as output on the console.
Advertisements