后浪云Python教程:python中AttributeError异常的介绍

后浪云Python教程:python中AttributeError异常的介绍插图

1、当你访问一个对象的属性,但是这个属性没有被这个对象定义时,导致AttributeError

2、AttributeError的错误信息行告诉我们特定对象类型没有访问属性。点击文件链接可以快速定位到具体的错误代码的位置。

实例

a_list  = (1, 2)
a_list.append (3)
运行之后抛出异常信息
Traceback  (most  recent  call  last ):
  File  "/Users/chenxiangan/pythonproject/demo/exmpale.py", line  2, in  <module>
    a_list.append (3)
AttributeError: 'tuple' object  has  no  attribute  'append'

以上就是python中AttributeError异常的介绍,希望对大家有所帮助。更多Python学习指路:后浪云python教程

THE END