summaryrefslogtreecommitdiffhomepage
path: root/python.html.markdown
diff options
context:
space:
mode:
authorEvgeniy Ginzburg <Nad.Oby@gmail.com>2014-08-05 17:41:41 +0300
committerEvgeniy Ginzburg <Nad.Oby@gmail.com>2014-08-05 17:41:41 +0300
commit611a00b5108e7a81eedbdba37a816df060ef3eca (patch)
treeccc09e48309f244534c9cdb64bd270fe5460be93 /python.html.markdown
parent57036f128f5e874116729e67d8a77cd763f206d5 (diff)
parent4541a0f450cb3ee29b4c11c727b1dc17e3f436ca (diff)
Merge https://github.com/adambard/learnxinyminutes-docs
Diffstat (limited to 'python.html.markdown')
-rw-r--r--python.html.markdown14
1 files changed, 10 insertions, 4 deletions
diff --git a/python.html.markdown b/python.html.markdown
index aa077e57..b7d5895a 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -334,6 +334,10 @@ try:
raise IndexError("This is an index error")
except IndexError as e:
pass # Pass is just a no-op. Usually you would do recovery here.
+except (TypeError, NameError):
+ pass # Multiple exceptions can be handled together, if required.
+else: # Optional clause to the try/except block. Must follow all except blocks
+ print "All good!" # Runs only if the code in try raises no exceptions
####################################################
@@ -519,11 +523,13 @@ def double_numbers(iterable):
# Instead of generating and returning all values at once it creates one in each
# iteration. This means values bigger than 15 wont be processed in
# double_numbers.
-# Note range is a generator too. Creating a list 1-900000000 would take lot of
-# time to be made
-_range = range(1, 900000000)
+# Note xrange is a generator that does the same thing range does.
+# Creating a list 1-900000000 would take lot of time and space to be made.
+# xrange creates an xrange generator object instead of creating the entire list like range does.
+_xrange = xrange(1, 900000000)
+
# will double all numbers until a result >=30 found
-for i in double_numbers(_range):
+for i in double_numbers(_xrange):
print(i)
if i >= 30:
break