热线电话:13121318867

登录
2019-03-06 阅读量: 593
python常见的报错信息

python主要有两种错误:

  • 语法错误:也称为解析错误,最基本的。当Python解析器无法理解一行代码时出现。
  • 例外:执行期间检测到的错误。例如 - ZeroDivisionError。

异常错误列表:

  • IOError:如果无法打开文件
  • KeyboardInterrupt:当用户按下不需要的键时
  • ValueError:当内置函数收到错误的参数时
  • EOFError:如果在没有读取任何数据的情况下命中文件结尾
  • ImportError:如果找不到模块

例子:

# Python code to illustrate

# working of try()

def divide(x, y):

try:

# Floor Division : Gives only Fractional Part as Answer

result = x // y

print("Yeah ! Your answer is :", result)

except ZeroDivisionError:

print("Sorry ! You are dividing by zero ")

# Look at parameters and note the working of Program

divide(3, 0)

输出:

Sorry ! You are dividing by zero
13.6036
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子