# Example, Python tuple looks like... gender = ( 'female', 'male', 'prefer not to share') car_available = ( 'Ford', '1200cc', 'auto', 21243 , 2009) type(car_available)
Tuple used to store more than one element. In Python, tuple is written with round brackets ( ) - (i.e. parentheses). Elements are separated by comma , character. Tuple can hold different data types in same tuple. Tuple can have duplicate items.
Tuple Vs ListDifferences:
Tuple is immutable. It means, you can not modify its content once it is created. List is mutable and its content can be modified (add/remove/update).Similarities:
Both are sequence data types. So, they can be used to store multiple elements together. Elements accessed by index.
- class 'tuple'
Working with Tuple
Since Tuple is immutable, following operations can be done using workaround: Replace element, Append at end, Extend at end, Insert at start/front, in middle, at end, Remove element by Value, Remove element by Index, Remove All.