Tuples
Tuples
A tuple is an ordered sequence of elements of different data types, such as integer, float,
string, list or even a tuple.
Elements of a tuple are enclosed in parenthesis (round brackets) and are separated by
commas.
Tuple of integers : tuple1 = (1,2,3,4,5)
Tuple of mixed data types : tuple2 =('Economics',87,'Accountancy',89.6)
Tuple with list as an element : tuple3 = (10,20,30,[40,50])
Tuple with tuple as an element : tuple4 = (1,2,3,4,5,(10,20))
Like list and string, elements of a tuple can be accessed using index values, starting from 0.
If there is only a single element in a tuple then the element should be followed by a comma.
If we assign the value without comma it is treated as integer.
Tup5 = (10) ; type(Tup5) int
Tup6 = (10,) ; type(Tup6) tuple
Assignment of tuple is a useful feature in Python. It allows a tuple of variables on the left side
of the assignment operator to be assigned respective values from a tuple on the right side.
(N1,N2,N3) = (20,40,60)