On Thu, Apr 11, 2013 at 8:41 PM, w qj <after19...@gmail.com> wrote:
> I found this under Windows Python3
>>>> l="http://f/";
>>>> l[-1] is not '/'
> False
>>>>
>
> and this under Linux Python3
>>>> l = "http://ff.f/";
>>>> l[-1]
> '/'
>>>> l[-1] is not '/'
> True
>
> It's Looks like a python bug?

No, this is not. The 'is' and 'is not' tests in Python are for
checking the identities of Python objects - a string, a single
character, a single number, everything is an object.

So for example:

>>> a=1
>>> b=1
>>> a is b
True
>>> id(a) == id(b)
True

When you perform the check, 'a is b', you are actually checking id(a)
== id(b). In this case, since I am really referring to the same
object, 1 with two different bindings - the identifier is the same.

In  your case, the check 'failed' on Windows and 'passed' on Linux, is
because in one case, the identifiers were the same, and in another
case it wasn't.  So, when are identifiers same and when not? That
depends on the type of object - mutable or immutable. You may want to
read up on Python's data model to learn more about this. Also, more on
"string interning" here. [1]

[1] http://stackoverflow.com/questions/15541404/python-string-interning

HTH,
Amit.



--
http://amitsaha.github.com/
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to