Python - Update Tuples
Tuples are unchangeable, meaing that you cannot change, add, or remove items once the tuple is created.[۱]
But there are some workarounds.
Change Tuple Values
Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called.
But there is a workaround. You can convert the tuple into a list, change the list, and convert the list back into a tuple.
Add Items
Once a tuple is created, you cannot add items to it.
Just like the workaround for changing a tuple, you can convert it into a list, add your item(s), and convert it back into a tuple.
Convert the tuple into a list, add "orange", and convert it back into a tuple:
Remove Items
Tuples are unchangeable, so you cannot remove items from it, but you can use the same workaround as we used for changing and adding tuple items:
Convert the tuple into a list, remove "apple", and convert it back into a tuple:
Or you can delete the tuple completely:
منابع آموزشی