September 27

Tuples

Tuple is sequence of values separated with comma and enclosed in parentheses.Tuple is very similar to List like accessing values,negative indices and slicing work same as list.
Difference between Tuples and lists are, you can not modify tuples unlike lists that why tuple is immutable object and tuples enclosed with parentheses whereas lists use square brackets.

Key features of Tuple:

  • You modify or add element to a tuple
  • You cannot remove element from a tuple
  • Tuples are faster than lists, so if you need to define constant set of values use tuples.
  • Tuples are immutable.You can use tuples as key of dictionary but cannot use list as key
  • tuple assignment is more elegant
  • You have to add comma for single value tuple