Page 99 - tp_Modula_v2.0
P. 99
DIFFERENCE BETWEEN LIST AND TUPLE
List Tuple
A list is a sequence of multiple values in an A tuple is a collection of objects which is
ordered sequence. ordered.
List is enclosed in square brackets []. Tuples are enclosed in parenthesis ( ).
Elements of the list can be changed. Elements of the tuple cannot be changed.
List has the variable length. Tuple has the fixed length.
List is mutable. Tuple is immutable.
Lists are slower due to mutability. Tuples are faster due to immutability.
SOME MORE PROGRAMS
Program 11: To print the entire tuple.
Program11.py
File Edit Format Run Options Window Help
tup1 = ('sst', 'chemistry', 2010, 2022);
print(tup1)
On running the above program, you will get the following output:
Output
('sst', 'chemistry', 2010, 2022)
Program 12: To use tuple method count and index.
Program12.py
File Edit Format Run Options Window Help
tup=(2,5,7,8,2,1)
print(tup.count(2))
print(tup.index(7))
On running the above program, you will get the following output:
Output
2
2
Tuple in Python 97

