top of page

Python Mutable & Immutable Data Types

Python data types are categorised into two category – Mutable and Immutable.

Python Mutable and Immutable Data Types


Python data types are categorised into two category – Mutable and Immutable.

Immutable Data Type

Integers, floating point number, Booleans, strings, and tuples are the immutable type. These data types never changes their value in place.

When you change the value of above mentioned data type variable, it will change the reference pointed by variable.

In Python variable names are stored as references to a value-object. Each time we change the value, the variable’s reference memory address changes.

Mutable Data Type

In Python, only three types are Mutable. Mutable means value can be changed in place.

Lists, Dictionaries, and Sets

3.7 Equality (==) and Identity (is):- Their Relation

Equality Operator (==) returns True, if two variables having same value, while Identity (is) operator returns True, when two variables are referring to same value i.e. same memory location.

In Python, if the is operator returns True for two objects, then the == operator must return True for the same objects, i.e. if two references refer to the same memory address, then their values are always same.

But in some conditions, two objects having the same value and == operator returns True, but the is operator returns False.

Reason: Actually, in some cases, Python creates two different objects that both store same value, but referring different addresses.

Case 1: input of strings from the console.

Case 2: writing integers literals with many digits i.e. very big number

Case 3:  writing floating-point and complex literals.

Python Mutable Immutable
bottom of page