Understanding python functions - Instant Python tutorial
wildemar at freakmail.de
Fri Jul 13 18:41:51 CEST 2007
Chris Carlen wrote:
> Let's go back the statement:
> x = [1,2,3]
> Do we then say: "[1,2,3] is x" or is it the other way around: "x is
> [1,2,3]" ???
This will yield 'False', because 'is' checks for *identity* not
equality. In your case you assign a list the name 'x' and then check
(via the 'is' operator) if it is the same object as another (newly
created) list. While they are equal (same class and contents) they are
not the same.
x = [1, 2, 3]
y = [1, 2, 3]
x == y
x is y
Then you'll see.
> This is actually completely ridiculous, since I am me, not my name. The
> name refers to me. I get that. Yet our spoken language puts it in a
> way which is backwards.
To stress the point: "a is b" has the same meaning as "b is a". It does
not check for "being a certain thing" (as in "Archimedes is a human")
but rather for "one thing beeing the exact same as the other" (as in
"Superman is Clark Kent").
More information about the Python-list