0% found this document useful (0 votes)
0 views4 pages

Mutable vs Immutable in Python

In Python, mutable objects can be modified after creation, including lists, dictionaries, and sets, while immutable objects cannot be changed once created, such as integers, floats, strings, and tuples. Examples illustrate how mutable lists can be altered and how immutable strings can only be reassigned. Understanding these concepts is essential for effective programming in Python.

Uploaded by

alok895734
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Mutable vs Immutable in Python

In Python, mutable objects can be modified after creation, including lists, dictionaries, and sets, while immutable objects cannot be changed once created, such as integers, floats, strings, and tuples. Examples illustrate how mutable lists can be altered and how immutable strings can only be reassigned. Understanding these concepts is essential for effective programming in Python.

Uploaded by

alok895734
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Mutable vs

Immutable in
Python
In Python, the term "mutable" and "immutable" refer to the ability
of an object to be changed after it is created.
Understanding the Concept
1 Mutable Objects 2 Immutable Objects
These are objects that These are objects that
can be modified after cannot be changed once
they are created, such as they are created, such as
lists and dictionaries. integers, floats, and
Example:- strings.
Example:-
my_list=[1,2,3]
st="hello"
my_list[0]=10
st=st+"world"
print(my_list)
print(st)
o/p:-10,2,3
o/p:-hello world
Mutable Data Types
Lists Dictionaries Sets

Elements can be added, removed, Key-value pairs can be added, Elements can be added or removed
or modified after creation. removed, or modified after after creation.
creation.
Immutable Data Types

Integers Floats
Cannot be changed after creation. Cannot be changed after creation.

Strings Tuples
Cannot be changed after creation. Cannot be changed after creation.

You might also like