Understanding Tuple data structure
Table of content
- Tuple
- How to define tuple
- Access tuple elements
- Tuple containing mutation
- Tuple methods
Tuple
Tuple is an immutable inbuilt data structure, once created can't be modified. We can define tuple using () round Bracktes in Python.
How to define tuple?
Access tuple elements
We index the tuple to access element
Tuple cannot be modified.
Tuple containing mutation
Tuple are immutable but can contain mutable data elements like list. We can loop on tuple using for loop.
Methods
1) tuple.count(x) : returns count of occurrence of element. The number of times the element is present in the tuple.
2) tuple.index(x) : returns index of value. (first occurrence from left)
Thank you folks. If you like this Python 3 post, please do checkout my other post on Django with Python 3 series