Python stores all data in the form of objects. Each object in the python contains 3 things.
1. Identity
2. Type
3. Value
Identity of an object cannot be changed. We can understand term Identity as address of the object in the memory.
id() – is the syntax to fetch the identity or memory address of an object. Hence, this cannot be changed
example:
input: id(variable_name)
output: 139741198954576
we can use is operator to compare two objects’ identity and check if both objects are same or not. This function returns the value in integer.
Type of an object decides the operations which can be supported by it. what type of values the object can store in it. Similar to Identity the Type of an object cannot be changed and its not recommended.
syntax: type()
example:
input: type(variable_name)
output: tuple
Value of an object can be changed if the object is mutable; value cannot be changed if the object is immutable. Type of an object determines its mutability.
Dictionaries, Lists and Sets are mutable.
Numbers, Integers, Strings, Tuples, Floats are immutable.
We need to understand that an immutable container can hold a m
value of an immutable container object which contains its reference to a mutable object