6. Tuple

A Tuple is a sequence datatype that is similar to the list. The tuple consists of a number of values separated by commas. The main different between list and tuples are:

  1. lists are enclosed in square brackets([ ]) while tuples are enclosed by parenthesis (( )) .

  2. In list elements size can be changed but tuples can be considered as a read only.

Example:

first_tuple=('ram', 123, 2.4, 'shyam', 679.5)

small tuple=(111, 'Tom')

print(first_tuple)

print(small_tuple)

print(first_tuple + small tuple)


Built in Tuple Function

tuple1=('ram', 123, 2.4, 'shyam', 679.5)


  1. len() : print(len(tuple1)

  2. max(tuple1)

  3. min(tuple1)

  4. tuple(seq)


list1= ['abcd', 147, 2.43, 'Tom']

printf("Tuple :", tuple(list))