From d164d5a56ea003c003ff65a0d316a61b31571481 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 27 Jun 2013 18:18:05 -0700 Subject: [PATCH] Minor fixes to python doc --- python.html.markdown | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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