learning python ...
hw
hw at adminart.net
Tue May 25 00:08:57 EDT 2021
On 5/25/21 12:37 AM, Greg Ewing wrote:
> On 25/05/21 9:27 am, Cameron Simpson wrote:
>> On 24May2021 16:17, hw <hw at adminart.net> wrote:
> >
>>> Or it doesn't forget
>>> about the old one and the old one becomes inaccessible (unless you
>>> have a reference to it, if there is such a thing in python). How do
>>> you call that?
>>
>> You're conflating values
>> (objects, such as an int or a string) with variables (which _are_
>> references in Python,
>
> I think hw might have meant the C++ notion of a reference to
> a *variable*. There is no equivalent of that in Python.
yes, or a reference in perl
> Python does have references to *objects*. All objects live on
> the heap and are kept alive as long as there is at least one
> reference to them.
>
> If you rebind a name, and it held the last reference to an
> object, there is no way to get that object back.
Are all names references? When I pass a name as a parameter to a
function, does the object the name is referring to, when altered by the
function, still appear altered after the function has returned? I
wouldn't expect that ...
> On the other hand, if you shadow a name, the original name
> still exists, and there is usually some way to get at it,
> e.g.
>
> >>> int = 42
> >>> int
> 42
> >>> __builtins__.int
> <class 'int'>
> >>>
>
You mean built-in objects never go away, even when they are no longer
referenced?
More information about the Python-list
mailing list