运行python 时出现TypeError: obj() takes no parametrs
运行以下代码时出现TypeError: obj() takes no parametrs
root cause: init前后各有两个下划线"_", 但代码中只写了一个
class Dog():
def _init_(self,name,age):
self.name=name
self.age=age
def sit(self):
print(self.name.title()+" is now siting.")
def roll_over(self):
print(self.name.title()+" rolled over!")
my_dog=Dog('haha',6)
print("my dog's name is "+my_dog.name.title()+".")
print("my dog is "+str(my_dog.age)+" years old")
my_dog.sit()
my_dog.roll_over()
正确代码应该是:
class Dog():
"""一次模拟小狗的简单测试"""
def __init__(self,name,age):
"""初始化属性name and age"""
self.name=name
self.age=age
def sit(self):
"""模拟小狗听到命令时蹲下"""
print(self.name.title()+" is now siting.")
def roll_over(self):
"""模拟小狗听到命令时打滚"""
print(self.name.title()+" rolled over!")
my_dog=Dog('haha',6)
print("my dog's name is "+my_dog.name.title()+".")
print("my dog is "+str(my_dog.age)+" years old")
my_dog.sit()
my_dog.roll_over()
- python中新手定义类时出现的致命的小问题之TypeError: object() takes no parameters
- Python3问题TypeError: object() takes no parameters
- Python开发调用语音模块报错:TypeError:NoneTypetakesnoarguments
- python中super出现的TypeError: must be type, not classobj 原因及解决
- Python中3+版本运行2+版本程序出现TypeError: a bytes-like object is required, not 'str'之读取PDF中的图片
- python中super出现的TypeError: must be type, not classobj 原因及解决
- python出现super.__init__:TypeError:must be type,not classobj
- Python中报错提示:TypeError: Student() takes no arguments
- python:TypeError: this constructor takes no arguments解决方法
- python中super()出现的TypeError: must be type, not classobj
- Python_TypeError:object() takes no parameters
- TypeError: this constructor takes no arguments(Python 学习遇到的错误1)
- python "TypeError: object() takes no parameters"
- 在Python中TypeError: object() takes no parameters新手问题的解决办法
- [转载]python中super出现的TypeError: must be type, not classobj 原因及解决
- linux下运行python3出现TypeError: a bytes-like object is required, not 'str'
- 解决"学习python-flask教程,下载源码运行的时候出现:TypeError: 'bool' object is not callable 错误代码:"
- 解决Python中出现的TypeError: object of type 'zip' has no len()
- Python 3.5 + PyInstaller 3.2.1打包exe出错,TypeError: read() takes no keyword arguments
- python之TypeError: this constructor takes no arguments