The final built-in data types is the tuple.Python tuples work exactly like Python lists except they are immutable, i.e. they can’t be changed in place.They are normally written inside parentheses to distinguish them from lists(which use square brackets),but as you’ll see,parentheses aren’t always necessary.Since tuples are immutable,their length is fixed.to grow or shrink a tuple,a new tuple must be created.

Here’s a list of common operation for tuples:

⦁	() An empty tuple
⦁	t1 = (0, )A one-item tuple(not an expression)
⦁	t2=(0,1,2,3) A four-item tuple
⦁	t3=0,1,2,3 Another four-item tuple(same as prior line,just minus the parenthesis)
⦁	t3=('abc',('def','ghi')) Nested tuples
⦁	t1[n],t3[n][j] Index
⦁	t1[i:j],Slice
⦁	len(t1) Length
⦁	t1+t2 Concatenates
⦁	t2*3 Repeat
⦁	for x in t2,Iteration
⦁	3 in t2 Membership
Translate »