Can global variable be passed into Python function?

Chris Angelico rosuav at
Fri Feb 28 12:51:28 CET 2014

On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa <marko at> wrote:
> Chris Angelico <rosuav at>:
>> String literals will often be interned if they look like (especially,
>> if they *are*) identifiers, so if you want to prevent other strings
>> from happening to match, you can't trust 'is'.
>> [...]
>> If you're using strings as state values, you should be using == to
>> compare them. Nothing else is safe.
> You didn't quite understand the use case. You would never ever do things
> like:
>> >>> a.state="<<INIT>>"
> You'd only refer to the state names symbolically:
>    a.state = a.INIT

In theory, yes. If that's all people will ever do, then you can safely
use == to check. Why are you using is? To prevent the case where some
other random string will happen to compare equal. So I stuffed some
other random string in, and it was equal, and I proved that I could
make it identical as well.


More information about the Python-list mailing list