Professional Documents
Culture Documents
IP PythonTuple PDF
IP PythonTuple PDF
Tuple List
Tuple is immutable i.e., its contents cannot List is mutable i.e., its contents can be changed or
be changed or removed. removed.
The elements in tuple are within parentheses. The elements in List are within square brackets.
Example, T1 = (‘Manish’, 12, 345) Example, L1 = [‘Manish’, 12, 345]
Basic Tuple Operations
Operation Expression Results
Concatenation a = (2, 4, 6)
b = (5, 7, 9)
c=a+b
print ( c, b, a, sep="~~") (2, 4, 6, 5, 7, 9)~~(5, 7, 9)~~(2, 4, 6)
Repetition t = (“welcome”,)
print ( t * 2 ) (‘welcome’, ‘welcome’)
Membership nos = ( 1, 3, 5,7 )
4 in nos False
3 in nos True
2 not in nos True
Tuple Slicing
0 1 2 3
Like string indices, tuple indices also start at 0, and can be sliced.
‘monica’ 12 ‘seema’ (13,17)
T1 = ( ‘monica’,12,’seema’, (13,17 ) )
-4 -3 -2 -1