Can a simple a==b 'hang' in and endless loop?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Jan 18 17:27:10 EST 2006


On Wed, 18 Jan 2006 15:29:24 +0100, Claudio Grondi wrote:

> The problem here is, that I mean, that in Python it makes no sense to 
> talk about a value of an object, because it leads to weird things when 
> trying to give a definition what a value of an object is.

Python object: 1
The value of that Python object: the int 1

Python object 4.7
The value of that Python object: the float 4.7

Python object "abc"
The value of that Python object: a string consisting of characters a, b
and c.

Python object [1, 4.7, "abc"]
The value of that Python object: a list containing objects 1, 4.7 and "abc".


Where's the problem?


> It seems, that in Python there is a lack of operator able to compare 
> values as it is the case in C and Javascript, simply because in Python 
> there are no really such things as values, so there is no need to 
> compare them.

>>> 1 == 1
True
>>> 4.7 == 1
False

Works for me.


> The higher level of abstraction/indirection in Python results in making
> the concepts of 'value', 'having a value' or 'comparing values' useless,
> where it helps in C to express the difference between address and
> content at that address and to distinguish between the information
> telling _what_ is stored in memory and the information about _where_ it
> is stored.

In Python, you never care _where_ anything is stored. The id() function
returns the unique ID of an object, which as an implementation detail may
be the actual memory address, but that's just an implementation detail. In
any case, given a memory address, you can't do anything with that
knowledge.


-- 
Steven.




More information about the Python-list mailing list