Difference between List and Tuples in Python.

PythonServer Side ProgrammingProgramming

List

List is a container to contain different types of objects and is used to iterate objects.

Example

list = ['a', 'b', 'c', 'd', 'e']

Tuples

Tuple is also similar to list but contains immutable objects. Tuple processing is faster than List.

Example

tuples = ('a', 'b', 'c', 'd', 'e')

Following are the important differences between List and Tuple.

Sr. No.KeyListTuple
1TypeList is mutable.Tuple is immutable.
2IterationList iteration is slower and is time consuming.Tuple iteration is faster.
3Appropriate forList is useful for insertion and deletion operations.Tuple is useful for readonly operations like accessing elements.
4Memory ConsumptionList consumes more memory.Tuples consumes less memory.
5MethodsList provides many in-built methods.Tuples have less in-built methods.
6Error proneList operations are more error prone.Tuples operations are safe.
raja
Published on 28-Nov-2019 15:04:16
Advertisements