Tricks to do "enums"?
Joal Heagney
sctheagn at kraken.itc.gu.edu.au
Mon May 8 03:23:32 EDT 2000
Courageous wrote:
> > "==" works just as well. Python smart enough to try a pointer
> > compare first. The code path is almost the same so I doubt there
> > would be much speed gained by using "is".
>
> Well that's cool. The next question is...
>
> Do all string constants which are lexically equivalent obey
> the identity rule? IOW, does the python byte compiler know
> how, upon compilation, to make two seperate instance of
> "joe" point to the same single instance?
I think this is true. Looking up my "Programming Python" book, I tested
this with the 'is' operator.
x = 'joe'
y = x
x is y
gave 1.
x = 'may'
y = 'may'
x is y
gave 1.
Trying this on lists
x = ['joe', 'may', 'bob']
y = ['joe', 'may', 'bob']
x is y
gave 0
y = x
y
gave ['joe', 'may', 'bob']
x is y
gave 1.
Joal Heagney/AncientHart
More information about the Python-list
mailing list