# HG changeset patch
# User Atul Varma 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. Python is technically like JavaScript in that semicolons are optional,
+but its community prescribes the opposite convention: that is,
+semicolons should never be used to delimit statements unless
+absolutely necessary. This is yet another decision 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. 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: This makes it easy and fun to explore the language and its environs. In most cases, this is for the best, as it makes debugging easier. If
-you really need to find out if an object has a particular attribute,
-however, you can use the hasattr() function: In most cases, this is for the best, as it makes debugging easier. Python also has an analog to JavaScript's null: it's called
None. As mentioned earlier, this string is called the docstring, and is
+ As mentioned earlier, this string is called the docstring; it's
actually attached to the function object as its __doc__ attribute.
Creating docstrings for your functions not only helps document your
code, but also makes it easier for Python users to interactively
@@ -401,8 +400,8 @@
there
- Strings are just sequences of characters, so they can be used
-similarly: Strings are just sequences of single-character strings, so they can be
+used similarly: Keys for dictionaries can actually be any immutable type; this means
+that, for instance, tuples can be used as keys: But lists can't: Python dictionaries generally aren't used to create arbitrary objects
like they are in Javascript; they don't have prototypes, nor do they
have meta-methods. Instead, classes are used to do that sort of
thing. In some ways, this is unfortunate, since the simplicity of
conflating objects with dictionaries, as JavaScript and Lua do, makes
-understanding and using them easier.The Interactive Shell
@@ -120,16 +123,20 @@
->>> print "a string".join.__doc__
-S.join(sequence) -> string
+>>> help("a string".join)
+Help on built-in function join:
<BLANKLINE>
-Return a string which is the concatenation of the strings in the
-sequence. The separator between elements is S.
+join(...)
+ S.join(sequence) -> string
+<BLANKLINE>
+ Return a string which is the concatenation of the strings in the
+ sequence. The separator between elements is S.
+<BLANKLINE>
-
+
->>> hasattr("a string", "foo")
-False
-
-
+
>>> for c in "boof":
@@ -535,12 +534,29 @@
'Hello bob, I need 5 dollars.'
+
+
+>>> a = {(1,2) : 1}
+
+
+
+>>> b = {[1,2] : 1}
+Traceback (most recent call last):
+...
+TypeError: list objects are unhashable
+
+
If you have any suggestions or comments regarding this tutorial, +please feel free to post them to this blog post. Thanks!
+