Skip to content

Commit 8bd1d30

Browse files
author
Amogh Singhal
authored
Update Python_Programming_Quiz.md
1 parent 710b61e commit 8bd1d30

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Python_Programming_Quiz.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,23 @@ And this is how extend() works:
303303
>>> list1
304304
[1, 2, 3, 4, 5, 6, 7, 8]
305305
```
306+
307+
#### 16. Explain `try`, `raise` and `finally`.
308+
309+
These are the keywords we use with __exception-handling__.<br>
310+
- We put risky code under a `try` block
311+
- Use the `raise` statement to __explicitly raise an error__
312+
- Use the `finally` block to put code that __we want to execute anyway__.
313+
314+
```
315+
>>> try:
316+
print(1/0)
317+
except ValueError:
318+
print("This is a value error")
319+
finally:
320+
print("This will print no matter what.")
321+
322+
# OUTPUT:
323+
# This will print no matter what.
324+
```
325+
Because in the try block we got a __DivisionByZeroException__ and not ValueError, so that is not caught and `finally` block is executed.

0 commit comments

Comments
 (0)