tuple
There are 4 collection data types in py:
Lists: Is a collection which is ordered and changeable. Allows duplicate members
Tuple: is a collection which is ordered and unchangeable. Allows duplicate members
Set: is a collection which is unordered and unindexed. No duplicate members
Dictionary :is a collection which is unordered, changeable and indexed. No duplicate members.
To create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.
Possible values
type() == <class ‘tuple’>
output: (‘orange’, ‘kiwi’, ‘melon’)
Change Tuple Values. Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called.
Get Dosiik1’s stories in your inbox
Join Medium for free to get updates from this writer.
But there is a workaround. You can convert the tuple into a list, change the list, and convert the list back into a tuple.
output: (“apple”, “kiwi”, “cherry”) changes: banana changed to kiwi
1st way to add new items: Convert into a list
2nd way to add new items: Add tuple to a tuple
To delete items we can use append() method, but after converting tuple to list.
Also we can delete the tuple completely







