Page 83 - Modular v1.1 Pyhton
P. 83
On running the above program, you will get the following output:
Clickipedia
Items in a tuple can be repeated, i.e., tuple may contain duplicate items.
Syntax to create a tuple:
tup= (value1, value2, value3, ...)
To create an empty tuple: tup= tuple( )
To create a tuple with single element: tup= (1,)
To create long tuple: tup = (0, 1, 2, 3, 4 , 5, 6, 7, 8, 9 10, 11, 12, 13,
14, 15)
To create nested tuple: tup = (1,2, (3,4))
To create tuple by using built-in tuple type object: tup = tuple(<sequence>)
Where, sequence is an object which includes strings, lists and tuples.
>>>tup= tuple('orange')
>>>tup
('o', 'r', 'a', 'n', 'g','e') #tuple tup is created from other sequence-
a string 'orange'.
ACCESSING A VALUE IN A TUPLE
To access values in a tuple, use the square brackets along with the index number for reference.
So, you can access the tuple element just like you access a list’s or string’s element.
Program 2: To access a value in tuple.
Tuple in Python 81

