[Tutor] Why is an instance smaller than the sum of its components?
Danny Yoo
dyoo at hashcollision.org
Tue Feb 3 23:25:54 CET 2015
>>
>> Summary questions:
>>
>> 1 - Why are foo's and bar's class sizes the same? (foo's just a nop)
>
>
> i'm not sure on this one.
>
>> 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 needs correction. I think you're thinking of regular functions.
But 'foo' and 'bar' are the names of the classes, so this is instance
construction.
To demonstrate the difference:
#####################################
>>> class foo(object): pass
...
>>> foo()
<__main__.foo object at 0x7f27655c0fd0>
#####################################
Compare what we see here to:
######################################
>>> def bar(): pass
...
>>> bar()
>>>
######################################
where the interactive evaluator is suppressing output of the None value.
More information about the Tutor
mailing list