From e6a289be491c9b0f1a7c2d5b364de0c4c8241bd9 Mon Sep 17 00:00:00 2001 From: Shashwat986 Date: Sat, 2 Aug 2014 19:37:28 +0530 Subject: Update python.html.markdown Added more details to try/except section. --- python.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index aa077e57..5bec5190 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 #################################################### -- cgit v1.2.3 From 65a1b6279fa1038efa013f64d98e7e947b527567 Mon Sep 17 00:00:00 2001 From: Shashwat986 Date: Tue, 5 Aug 2014 01:06:54 +0530 Subject: Update python.html.markdown range() is not a generator in python 2.x --- python.html.markdown | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 5bec5190..b7d5895a 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -523,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 -- cgit v1.2.3