赞
踩
1.IndexError: tuple index out of range
错误的原因是元组索引越界,因为后面format中的内容出现了赋值操作
1.TypeError: ‘int’ object has no attribute 'getitem’
会出现报错:
在python2中,input输入数字得到的就是int类型的数字,数字是不可以做下标取值,而python3中input输入都为字符串,而字符串可以下标索引
2.TypeError: unbound method say_hi() must be called with Person instance as first argument (got nothing instead)
原因:调用类报错,由于未添加括号情况下,未被认为是类的实例,故报此错
解决方法:在类名称后边加括号()
3.TypeError: ‘int’ object is not callable
原因:int对象不可调用,当变量名和函数名重复时,程序会默认调用Int型对象,Int对象没有什么调用可言,因此报错
解决方法:更改变量名或者更改函数名
4.TypeError: init() takes exactly 3 arguments (5 given)
原因:传输的参数不一致
在实现继承时,继承父类的方法,构造函数中也需要所用到的父类的参数。构造函数中包含调用父类构造函数。根据需要,不是必须。 子类并不会自动调用父类的__init__(),我们必须显式的调用它。
报错:
修改后运行正常:
1.SyntaxError: ‘break’ outside loop
原因:break只能在for循环和while循环中使用
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。