# HG changeset patch
# User Atul Varma The ++ and -- unary assignment operators aren't part of the
-Python language, and nor is JavaScript's === comparison operator
-(Python's == can be considered to behave like JavaScript's
-===).
There are some differences between Python and JavaScript when it comes +to equality; when using the == operator, for instance, Python +compares the value of objects rather than their locations in memory:
++++>>> a = [1, 2, 3] +>>> b = [1, 2, 3] +>>> a == b +True ++
The above expression is valid JavaScript code, but it would evaluate +to false. Python's is operator compares object identity:
++++>>> a is b +False ++
Functions are defined like so:
diff -r f1b7aa9f7699 -r acb80c6abaa8 PythonForJsProgrammers.txt --- a/PythonForJsProgrammers.txt Fri Jun 06 14:44:07 2008 -0700 +++ b/PythonForJsProgrammers.txt Tue Jun 10 23:09:08 2008 -0700 @@ -122,15 +122,19 @@ If there's a function you're interested in learning more about, you can look at the built-in documentation metadata associated with the -object--known as the `docstring`--by querying the object's ``__doc__`` -attribute. For instance, here's how to get help on the string -object's ``join()`` method: +object--known as the `docstring`--by calling the built-in ``help()`` +function on the object. For instance, here's how to get help on the +string object's ``join()`` method: - >>> print "a string".join.__doc__ - S.join(sequence) -> string + >>> help("a string".join) + Help on built-in function join:- Return a string which is the concatenation of the strings in the - sequence. The separator between elements is S. + join(...) + S.join(sequence) -> string + + Return a string which is the concatenation of the strings in the + sequence. The separator between elements is S. + This makes it easy and fun to explore the language and its environs. @@ -240,12 +244,7 @@ SyntaxError: invalid syntax The ``++`` and ``--`` unary assignment operators aren't part of the -Python language, and nor is JavaScript's ``===`` comparison operator -(Python's ``==`` can be considered to behave like JavaScript's -``===``). - -.. TODO: The last parenthetical is false; see Christopher Finke's -comment on my blog: http://www.toolness.com/wp/?p=45#comment-496 +Python language. Nothingness =========== @@ -269,6 +268,24 @@ Python also has an analog to JavaScript's ``null``: it's called ``None``. +Equality +======== + +There are some differences between Python and JavaScript when it comes +to equality; when using the ``==`` operator, for instance, Python +compares the `value` of objects rather than their locations in memory: + + >>> a = [1, 2, 3] + >>> b = [1, 2, 3] + >>> a == b + True + +The above expression is valid JavaScript code, but it would evaluate +to ``false``. Python's ``is`` operator compares object identity: + + >>> a is b + False + Functions =========