A tuple consists of a number of values represented by commas and enclosed within parentheses. We cannot change the values in a tuple after creating it. Actually, a tuple is a read-only data type.
The values stored in a tuple are accessed using indexes. The index of the first element is 0, and n-1 is the index of the last element, where n is the total number of elements. Like List, we can also use slice, concatenation, and repetition operations on the tuple.
Python program to demonstrate operations on a tuple
a=("Red","Green","Blue","Black") b=("white","Orange") print(a) print(a) # Prints first element of the Tuple print(a[1:3]) # Prints elements starting from 2nd till 3rd print(a*2) # Repeats the Tuple print(a+b) # Concatenates two Tuples
('Red', 'Green', 'Blue', 'Black') Red ('Green', 'Blue') ('Red', 'Green', 'Blue', 'Black', 'Red', 'Green', 'Blue', 'Black') ('Red', 'Green', 'Blue', 'Black', 'white', 'Orange')