user1308308
user1308308

Reputation: 345

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

Upvotes: 1

Views: 879

Answers (3)

Duncan
Duncan

Reputation: 95652

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.

Upvotes: 1

Maksym Polshcha
Maksym Polshcha

Reputation: 18358

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.

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599530

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.

Upvotes: 4

Related Questions