Q about object identity
Ethan Furman
ethan at stoneleaf.us
Fri Jun 6 16:27:01 EDT 2008
vronskij at gmail.com wrote:
> Hello,
>
> I am testing object identity.
>
> If I do it from the interpreter, I get strange results.
>
>
>>>>*print [] is []*
>
> *False*
>
>
>>>>print id([]), id([])
>
> 3083942700 3083942700
>
>
>
> Why is that? Isn't this an error?
>
>
> If I test it in a script, all is OK.
>
> #!/usr/bin/python
>
> a = []
> b = []
>
> print a == b
> *print a is b*
>
> print id(a), id(b)
>
> print id(None), id(None)
> print id(True), id(True)
>
>
> On my computer, I got these results:
>
> True
> *False*
> 3083769036 3083793516
> 135553336 135553336
> 135526444 135526444
>
> All as expected.
>
>
> jan bodnar
Assuming I'm not missing something obvious here, the results from the
script are the same as those from the interpreter -- the _is_ returns
False in both cases.
More information about the Python-list
mailing list