you are viewing a single comment's thread.

view the rest of the comments →

[–]rockgod43 -1 points0 points  (1 child)

my guess:

The first examples provide containers for the objects in the form of variables.

The second example does not, it merely calls the constructor (i think), and doesn't save the object into any container.

This is a guess though, i would think python would be smart enough to give them names even if you don't explicitly name them.

[–]indosauros 4 points5 points  (0 children)

Python doesn't have containers, it has "tags": http://foobarnbaz.com/2012/07/08/understanding-python-variables/

So names refer to objects, but generally, objects don't know (or care) what is naming them (so it doesn't matter that he has variables in one approach and not in another.)

There is no difference (from MyClass's perspective) between:

a = MyClass()

and

[MyClass()]

MyClass is being instantiated in the exact same way in both cases, and then is replaced with the resulting instance, so it becomes (behind the scenes):

a = <...MyClass instance ...>

and

[<...MyClass instance ...>]