Can global variable be passed into Python function?

Chris Angelico rosuav at gmail.com
Sat Mar 1 18:30:41 CET 2014


On Sun, Mar 2, 2014 at 4:23 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Ben Finney <ben+python at benfinney.id.au>:
>
>> No. I'm telling you that ‘is’ is *wrong* for comparing strings,
>> because it is unreliable.
>
> No, it isn't as long as the string object references have a common
> assignment "pedigree." Assignment (including parameter passing) is
> guaranteed to preserve identity of any object.

Of course it is, but your identity tests also depend on there NOT
being a common object when there is NOT an "assignment pedigree". The
positive is guaranteed; the negative is not. And if you don't care
about a false positive - that is, that some other string with the same
value matches - then what you actually want is equality, not identity,
comparison.

ChrisA



More information about the Python-list mailing list