bar
is just a reference to an already created object(foo
), doing bar=foo
means you created another reference to the same object.
In [62]: def foo():pass
In [63]: bar=foo
In [64]: spam=bar #another reference to foo function object
In [65]: spam.__name__,bar.__name__
Out[65]: ('foo', 'foo')
In [66]: spam is foo,bar is foo
Out[66]: (True, True)
In [67]: import sys
In [68]: sys.getrefcount(foo) # no of variable pointing to that object
Out[68]: 4 #3+1, 1 added by default by getrefcount()