Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit453ba97

Browse files
Update exception-handling.md
Fixed some errors...
1 parent490b0c9 commit453ba97

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

‎docs/cheatsheet/exception-handling.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ You can't divide by zero, that is a mathematical true, and if you try to do it i
2727
...print(dividend/ divisor)
2828
...
2929
>>> divide(dividend=10,divisor=5)
30-
#5
30+
#2
3131

3232
>>> divide(dividend=10,divisor=0)
3333
# Traceback (most recent call last):
@@ -45,7 +45,7 @@ Let's say we don't want our program to stop its execution or show the user an ou
4545
...print('You can not divide by 0')
4646
...
4747
>>> divide(dividend=10,divisor=5)
48-
#5
48+
#2
4949

5050
>>> divide(dividend=10,divisor=0)
5151
# You can not divide by 0
@@ -58,17 +58,22 @@ You can also handle multiple exceptions in one line like the following without t
5858
```python
5959
>>>defdivide(dividend ,divisor):
6060
...try:
61-
... var='str'+1
62-
...print(dividend/ divisor)
61+
...if (dividend==10):
62+
... var='str'+1
63+
...else:
64+
...print(dividend/ divisor)
6365
...except (ZeroDivisionError,TypeError)as error:
6466
...print(error)
6567
...
68+
69+
>>> divide(dividend=20,divisor=5)
70+
# 4
71+
6672
>>> divide(dividend=10,divisor=5)
67-
#5
73+
#`can only concatenate str (not "int") to str` Error message
6874

6975
>>> divide(dividend=10,divisor=0)
7076
# `division by zero` Error message
71-
# `can only concatenate str (not "int") to str` Error message
7277
```
7378

7479
##Finally code in exception handling

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp