What is Tuples?
Tuples are used to store multiple items in a single variable.
Characterstics of Tuples
- A tuple is a collection which is ordered and unchangeable and allow duplicate values.Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created.
- Tuples are written with round brackets.
- Tuple items are indexed, the first item has index [0], the second item has index [1] etc.
- When we say that tuples are ordered, it means that the items have a defined order, and that order will not change.
thistuple = ("apple", "banana", "cherry")
print(thistuple)
print(thistuple)
Tuple Items - Data Types
Tuple items can be of any data type:
tuple1 = ("apple", "banana", "cherry")
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)