python Identation Error/Syntax Eoor /Name Error

SyntaxError

(解释器)语法错误,比如缺了冒号,多了括号,少了引号等等

是唯一不是在运行时发生的异常

NameError

字面上的意思可以理解为在命名空间里找不到名字的错误。也就是:

python认为你使用了没有定义的变量

举个栗子:

>>> name = star
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'star' is not defined
>>> 

ZeroDivisionError

除数为0啦


IndexError

请求的索引超出范围

举个栗子:

>>> food=['cake','apple','meat']
>>> food[5]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> tools=[]
>>> tools[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> 

KeyError

你在字典里找一个并不存在的key,就是请求一个不存在的字典关键字


IOError

类似尝试打开一个不存在的磁盘文件


AttributeError

尝试访问未知的对象属性


IndentationError:

都知道Python是对格式要求很严格的,写了一些python但是也没发现他严格在哪里,今天遇到了IndentationError: unexpected indent错误我才知道他是多么的严格。
    以后遇到了IndentationError: unexpected indent你就要知道python编译器是在告诉你“Hi,老兄,你的文件里格式不对了,可能是tab和空格没对齐的问题,你需要检查下tab和空格了”。

http://blog.163.com/kylandzwr_39/blog/static/180285039201138103914582/




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值