mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Update python3.html.markdown
Added more info to try/except. Corrected some trivial bugs.
This commit is contained in:
parent
e6a289be49
commit
abc06a620b
@ -330,9 +330,12 @@ try:
|
|||||||
raise IndexError("This is an index error")
|
raise IndexError("This is an index error")
|
||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
pass # Pass is just a no-op. Usually you would do recovery here.
|
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
|
||||||
|
|
||||||
|
# Python offers a fundamental abstraction called the Iterable.
|
||||||
# Python's offers a fundamental abstraction called the Iterable.
|
|
||||||
# An iterable is an object that can be treated as a sequence.
|
# An iterable is an object that can be treated as a sequence.
|
||||||
# The object returned the range function, is an iterable.
|
# The object returned the range function, is an iterable.
|
||||||
|
|
||||||
@ -340,7 +343,7 @@ filled_dict = {"one": 1, "two": 2, "three": 3}
|
|||||||
our_iterable = filled_dict.keys()
|
our_iterable = filled_dict.keys()
|
||||||
print(our_iterable) #=> range(1,10). This is an object that implements our Iterable interface
|
print(our_iterable) #=> range(1,10). This is an object that implements our Iterable interface
|
||||||
|
|
||||||
i We can loop over it.
|
# We can loop over it.
|
||||||
for i in our_iterable:
|
for i in our_iterable:
|
||||||
print(i) # Prints one, two, three
|
print(i) # Prints one, two, three
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user