Tuple in Python
- Minu k
- Jun 27, 2022
- 2 min read

Tuple is a set of Python objects that looks a list. A tuple is a set of functions that can be of any type and are linked by integers. One of the four built-in data types in Python for preserving data collections is the tuple; the other three are list, set, and dictionary, each with a unique range of attributes and applications. A tuple is an irreversible, ordered collection.
A tuple's values are segregated syntactically by commas. It is more usual to define a tuple by containing the list of values in parentheses, while it is not needed. This made it easy to grasp Python tuples.
Creating a tuple
A tuple is described as a combination of values separated by commas and enclosed in small () brackets. Although employing commas is not essential, doing so is a good idea.
Advantages:
Because they cannot be updated, tuples are a write-protected collection. When we desire to keep safe read-only data that cannot be modified throughout our code, the use of tuples can be useful.
Tuples are a mixed collection because they can hold data of many data sorts.
Tuple has a rapid iteration because it is a read-only collection. (They have a continuous set of values since they are contained in a single block of memory and don't have extra space for storing objects.)
Disadvantage
Tuple's write restriction is both an advantage and a drawback as it inhibits us from exploiting it to add or remove certain parts. Thus, it only has a few utility cases.
Tuple is put on the heap and requires the garbage collector extra effort because it is a class.
You can also check out tuple and list difference in details .
Conclusion
Tuples can be generated even without parentheses and commas to distinguish the elements in the list. Here, we got to know about tuple in python , creating tuple , its advantages and disadvantages .
Comentarios