Puzzled by "is"

Paul Rudin paul.nospam at rudin.co.uk
Fri Aug 10 00:41:27 EDT 2007


John K Masters <johnmasters at oxtedonline.net> writes:

>
> OK fiddling around with this and reading the docs I tried:-
> a = 'qqqqqqqqqq' #10 q's
> b = 'qqqqqqqqqq' #10 q's
> a is b
> true
> c = 'q' * 10
> c
> 'qqqqqqqqqq' #10 q's
> d = 'q' * 10
> d
> 'qqqqqqqqqq' #10 q's
> c is d
> false
>
> So from what I've read "==" tests for equivalence, "is" tests for identity but
> that does not explain the behaviour above.
>

There's nothing especially to be explained, other than "that's the way
the compiler does it". Two equal string literals might be the same
object or they might not be. It's a language implementation detail.



More information about the Python-list mailing list