Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the variables in Python stored? [duplicate]

In C++, the local variables are stored in stack, while the datas created by new operator are stored in heap. So, what about the variables in Python? Where are they stored?

like image 374
injoy Avatar asked Jul 20 '13 17:07

injoy


People also ask

Where are the variables in a Python program stored?

It is called heap because it is a pile of memory space available to programmers to allocated and de-allocate. The variables are needed outside of method or function calls or are shared within multiple functions globally are stored in Heap memory.

What are duplicates in Python?

What are duplicates in a list? If an integer or string or any items in a list are repeated more than one time, they are duplicates.

Can set store duplicate values in Python?

Sets cannot contain duplicates. Duplicates are discarded when initializing a set. If adding an element to a set, and that element is already contained in the set, then the set will not change.


1 Answers

Copying from Python documentation:

Memory management in Python involves a private heap containing all Python objects and data structures. The management of this private heap is ensured internally by the Python memory manager. The Python memory manager has different components which deal with various dynamic storage management aspects, like sharing, segmentation, preallocation or caching.

like image 195
dkar Avatar answered Nov 01 '22 06:11

dkar