***python中的标准异常有很多,下面只是列举比较常见的几种情况,具体的看下面链接Python 异常处理 | 菜鸟教程 (runoob.com)https://www.runoob.com/python/python-exceptions.html
一、常见异常类型
1、数字运算异常
print(3/0) #ZeroDivisionError: division by zero
2、获取索引时异常
list=['张三','李四','王五','马六']
print(list[4]) #IndexError: list index out of range 索引是从0开始的
3、获取键时异常
dict={'first':'abandon','second':'bellow','third':'crazy','forth':'dish'}
print(dict['fifth']) #KeyError: 'fifth'
4、变量未声明异常
print(art_list) #NameError: name 'art_list' is not defined
5、语法错误异常
int a=20 #SyntaxError: invalid syntax
'''python中变量是没有数据类型的,而上述写法是在给变量设置类型'''
6、传入无效参数
num=int('Nice shoot')
print(num) #ValueError: invalid literal for int() with base 10: 'Nice shoot'
二、PyCharm的调式功能
以前在if-else,while,for-in循环中经常用到了调式,这里就不展示了