A tuple is an immutable sequence of objects of potentially different types.
Each object can be referred to using the square bracket index notation.
Tuples are defined using parenthesis (or the built-in function tuple):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

a=(1, 2)# tuple of two integers

b=1, 2# alternative way to define a tuple

a[0]=3# error: modifying an immutable tuple after its creation

a=(1, 2)# tuple of two integers

b=(1, "one")# tuple of an integer and a string

c=(a, b)# tuple containing two tuples

print(b[1])# prints the second element of b

print(c[0])# prints the first element of c

# Example: unpacking

t=(1, 2, 3)# tuple of three integers

(a, b, c)=t# copy first element of t to a, second to b, etc.

a, b, c=t# alternative syntax to accomplish the same thing

print(a)

print(b)

print(c)

# Example: nested tuples

t=(1, (2, 3))# tuple containing an integer and a tuple

# copy the first element of t to a, second to (b, c)