CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

VARIABLES AND MEMORY ALLOCATION IN PYTHON

VARIABLES AND  MEMORY ALLOCATION IN PYTHON

Variables and memory addresses in Python

Variable are Objects in Python:-

Python’s variables are not storage containers, rather Python variables are like memory references, they refer to the memory address where the value is stored.

Mutability/Immutability of data type:-

        Mutable Type                                                                                   Immutable Type
If the variable is referring to                                                              If the variable is referring to
mutable type, then any                                                                       immutable type, then any
changes in its value will not                                                              changes in its value will also
change the memory address                                                            change the memory address
of the variable.                                                                                     it is referring to.

Ex:- list, dictionary,                                                                            Ex:- int, float, decimal,
set and user-defined                                                                          bool, string, tuple, and
classes.                                                                                                range.

Interesting Facts:-

Python keeps integers from -5 to 256 as an array in memory. If you are using any object
that is referring to any of these int type numbers will use these stored numbers.





No comments:

Post a Comment