Tuple
A tuple is a collection which is ordered and unchangeable.
The important elements of the list syntax are:
o the round brackets/parentheses,
o the commas between elements, and
o the names in quotes.
thistuple = ("apple", "banana", "cherry")
List are changeable(mutable) and tuple are unchangeable
(immutable). That is the most important difference between the two
data types.
List
List items are ordered, changeable, and allow duplicate
values.
The important elements of the list syntax are:
• the square brackets,
• the commas between elements, and
• the names in quotes.
thislist = ["apple", "banana", "cherry", "apple", "cherry"]
Cont…
Tuples are a Python data structure that is similar to lists but with a
different syntax. The elements of a tuple are enclosed in parentheses
instead of square brackets.
Tuples are immutable, which means that once they are created, their
elements cannot be changed. This is different from lists, which are
mutable and can have elements added, removed, or modified.
Tuples are more efficient than lists for the computer to use,
particularly in larger programs.
Understanding the Tuple Data Type