简体   繁体   中英

How is memory allocated for empty list, tuple, dictionary?

I am new to python programming, as per OOps Concepts memory will allocated for every Object, in python programming, how the memory is allocated for [ ] , { } , ( ) objects without elements?

Thanks Mukthayr

If you're worrying about memory allocation for empty elements in Python, you're doing it wrong.

Python is a high-level language with automatic memory management. Unless you're trying to deal with huge amounts of data in a severely memory-restricted environment, you should not be thinking about this.

As the other answers say you don't need to know and you shouldn't care. In general empty lists and dictionaries are just like any other list or dictionary: indeed since you can mutate an empty list/dictionary it may later become non-empty.

However, the empty tuple is slightly different as in at least some implementations of Python it is a singleton value. It is exceedingly unlikely that this will ever matter to you, but there it is.

This depends on python interpreter implementation. And, actually, you can do nothing with that except for tuning garbage collection (see gc module ). Don't care, your interpreter do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM