Day10 常见的异常类型 PyCharm的调试

***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循环中经常用到了调式,这里就不展示了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值