|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 游戏小虾米 于 2017-7-19 23:17 编辑
Tip:
异常可以告诉哪里出了什么错
一,理论
http://bbs.fishc.com/thread-45814-1-2.html
Python标准异常总结
二,应用
1
>>> list = []
>>> assert len(list) > 0
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
assert len(list) > 0
AssertionError
2
>>> list.fishC()
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
list.fishC()
AttributeError: 'list' object has no attribute 'fishC'
3
>>> list[1]
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
list[1]
IndexError: list index out of range
4
>>> my_dict = {'one':1, 'six one eight':618}
>>> my_dict['eleven eleven']
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
my_dict['eleven eleven']
KeyError: 'eleven eleven'
5
>>> fishC
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
fishC
NameError: name 'fishC' is not defined
6
>>> f = open('F:\\readme.txt')
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
f = open('F:\\readme.txt')
FileNotFoundError: [Errno 2] No such file or directory: 'F:\\readme.txt'
7
>>> print 'cangjingkong'
SyntaxError: Missing parentheses in call to 'print'
8
>>> 1 + '1'
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
1 + '1'
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> 5 / 0
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
5 / 0
ZeroDivisionError: division by zero
三,课后练习 |
评分
-
查看全部评分
|