# HG changeset patch # User Atul Varma # Date 1212704247 25200 # Node ID 58b61d4a9883728410fad27988a63d62e3f18eae # Parent ea010fae8754cf0d5a0d99cf1e677f69ff280de6 Added more stuff. diff -r ea010fae8754 -r 58b61d4a9883 PythonForJsProgrammers.txt --- a/PythonForJsProgrammers.txt Thu Jun 05 15:04:18 2008 -0700 +++ b/PythonForJsProgrammers.txt Thu Jun 05 15:17:27 2008 -0700 @@ -11,29 +11,14 @@ .. _`borrowed directly from Python`: http://weblogs.mozillazine.org/roadmap/archives/2006/02/js_and_python_news.html -Interactive Shell -================= - -Python, when executed with no parameters, just presents an interactive -shell. It's similar to the SpiderMonkey shell and xpcshell if you're -familiar with those. The code examples in this tutorial will be -displayed as though they're being executed in it, like so: - - >>> 1 + 2 - 3 - >>> # Here's a comment that does nothing. - >>> print "hi!" - hi! - >>> print "This is a long " \ - ... "statement that spans multiple lines." - This is a long statement that spans multiple lines. - -The shell is also a useful way to explore Python's functionality; feel -free to just use it as a desk calculator to get used to it. - Whitespace ========== +This is coincidentally a good place to explain Python's design +philosophy, so please bear with me here as I go off on a bit of a +tangent--hopefully it will give you a better idea of whether this is a +language you'd like to use. + While not syntactically enforced by many languages, whitespace is semantically meaningful during the reading and writing of code. Take the following example of C-like code:: @@ -90,9 +75,32 @@ Also note that Python doesn't use semicolons, which is yet another language feature that reduces the cognitive burden on the programmer. +Indeed, many of the language features covered below were designed with +a very careful eye towards readability, reducing cognitive load, and +making the process of programming as enjoyable as possible. .. _`Don't Repeat Yourself`: http://en.wikipedia.org/wiki/Don%27t_repeat_yourself +The Interactive Shell +===================== + +Python, when executed with no parameters, just presents an interactive +shell. It's similar to the SpiderMonkey shell and xpcshell if you're +familiar with those. The code examples in this tutorial will be +displayed as though they're being executed in it, like so: + + >>> 1 + 2 + 3 + >>> # Here's a comment that does nothing. + >>> print "hi!" + hi! + >>> print "This is a long " \ + ... "statement that spans multiple lines." + This is a long statement that spans multiple lines. + +The shell is also a useful way to explore Python's functionality; feel +free to just use it as a desk calculator to get used to it. + Expressions =========== @@ -129,7 +137,7 @@ can only be used in statements in Python: >>> a = 5 # Assignment works in statements. - >>> a += 1 # Add-assignment works in statements. + >>> a += 1 # Add-assignment does too. 6 >>> if a = 1: # But you can't assign in an expression.