summaryrefslogtreecommitdiffhomepage
path: root/python.html.markdown
diff options
context:
space:
mode:
authorAdam <adam@adambard.com>2013-06-27 18:18:05 -0700
committerAdam <adam@adambard.com>2013-06-27 18:18:05 -0700
commitd164d5a56ea003c003ff65a0d316a61b31571481 (patch)
treeb079a1627e0ee704e88dca6699b52ebf5ac210d7 /python.html.markdown
parentaa18e7301c66eec70c40c11ed043205c78bbf3ab (diff)
Minor fixes to python doc
Diffstat (limited to 'python.html.markdown')
-rw-r--r--python.html.markdown16
1 files changed, 15 insertions, 1 deletions
diff --git a/python.html.markdown b/python.html.markdown
index eb8f5cb4..bf3739ba 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -233,12 +233,20 @@ while x < 4:
x += 1 # Shorthand for x = x + 1
# Handle exceptions with a try/except block
+
+# Works on Python 2.6 and up:
try:
# Use raise to raise an error
raise IndexError("This is an index error")
except IndexError as e:
pass # Pass is just a no-op. Usually you would do recovery here.
+# Works for Python 2.7 and down:
+try:
+ raise IndexError("This is an index error")
+except IndexError, e: # No "as", comma instead
+ pass
+
####################################################
## 4. Functions
@@ -272,7 +280,13 @@ keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
# You can do both at once, if you like
def all_the_args(*args, **kwargs):
- pass
+ print args
+ print kwargs
+"""
+all_the_args(1, 2, a=3, b=4) prints:
+ [1, 2]
+ {"a": 3, "b": 4}
+"""
# Python has first class functions