A tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.
Tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.
It is defined within parentheses () where items are separated by commas.
A. Accessing and Slicing a Tuple
You access a tuple the same way as you’d access a list. The same goes for slicing it.
B. A tuple is Immutable
Python tuple is immutable. Once declared, you can’t change its size or elements.
No comments:
Post a Comment