List:-
Lists are mutable objects which means you can modify a list object after it has been created. Tuples, on the other hand, are immutable objects which means you can't modify a tuple object after it's been created.
a = ['dog', 'cat', 'elephant', 'cow']
>>> print(a)
['dog', 'cat', 'elephant', 'cow']
>>> a
['dog', 'cat', 'elephant', 'cow']
The important characteristics of Python lists are as follows:
- Lists are ordered.
- Lists can contain any arbitrary objects.
- List elements can be accessed by index.
- Lists can be nested to arbitrary depth.
- Lists are mutable.
- Lists are dynamic.
Lists that have the same elements in a different order are not the same:
>>>>>> a = ['foo', 'bar', 'baz', 'qux']
>>> b = ['baz', 'qux', 'bar', 'foo']
>>> a == b
False
>>> a is b
False
>>> [1, 2, 3, 4] == [4, 1, 3, 2]
False
Lists that have the same elements in a different order are not the same:
>>> a = ['foo', 'bar', 'baz', 'qux']
>>> b = ['baz', 'qux', 'bar', 'foo']
>>> a == b
False
>>> a is b
False
>>> [1, 2, 3, 4] == [4, 1, 3, 2]
False
Lists Can Contain Arbitrary Objects
A list can contain any assortment of objects. The elements of a list can all be the same type:
>>> a = [2, 4, 6, 8]
>>> a
[2, 4, 6, 8]