[Tutor] Why is an instance smaller than the sum of its components?

Zachary Ware zachary.ware+pytut at gmail.com
Tue Feb 3 23:28:10 CET 2015


On Tue, Feb 3, 2015 at 3:59 PM, Emile van Sebille <emile at fenx.com> wrote:
> On 2/3/2015 1:12 PM, Jugurtha Hadjar wrote:
>> 2 - Why are foo() and bar() the same size, even with bar()'s 4 integers?
>
> neither foo() nor bar() return anything explicitly, so both return the
> default none

This is not correct, foo() and bar() return a foo instance and a bar
instance, respectively; not None.

For the OP: while this will probably be a nice exercise for learning
more about Python's internals, please keep in mind that 9 times out of
10 you won't need to worry about memory usage in Python, especially
not before you've proven to yourself that your program is using more
memory than is acceptable.

-- 
Zach


More information about the Tutor mailing list