Tuples 2
Tuples 2
NESTING OF TUPLE
Tuples can be placed inside other tuples.
When you add one or more tuples inside another tuple, the items in the
nested tuples are combined together to form a new tuple.
METHOD 1 METHOD 2
ACCESSING AND TRAVERSING A TUPLE
A tuple is a sequence of values which can be of any type and they
are indexed by integer.
Like lists, there could be positive indexing and negative indexing.
ACCESSING ELEMENTS
TRAVERSING A TUPLE
METHOD 1
METHOD 2
TUPLE OPERATIONS
SLICING
0 1 2 3 4 5 6 7 8
-9 -8 -7 -6 -5 -4 -3 -2 -1
TUPLE ADDITION / CONCATENATION
Python allow to join/concatenate two tuples.
New elements can be added to a tuple using +
operator.
TUPLE MULTIPLICATION / REPLICATION
The multiplication operator (*) is used for repetition of the tuple
‘in’ and ‘not in’ membership operators
TUPLE FUNCTIONS
len() – this function returns the length of the tuple. i.e
count the total number of elements of the tuple.
lists.
DISADVANTAGES OF USING TUPLE COMPARING TO LIST.