List is mutable or immutable in Python

Lists are mutable data types in Python because the elements of the list can be modified, replaced, and the order of elements can be changed even after the list has been created.

An example list is mutable or immutable in Python

Simple example code once a list has been created can be modified, replaced or order of elements can be changed

Python Lists are also dynamic.

lst = ['A', 'B', 'C', 'D']

lst[2] = "New"

print(lst)

Output: If the list is immutable then TypeError will throw by the compiler.

List is mutable or immutable in Python

Do comment if you have any doubts and suggestions on this Python List tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.