运行python 时出现TypeError: obj() takes no parametrs
来源:互联网 发布:在家兼职淘宝客服58 编辑:程序博客网 时间:2024/06/07 09:59
运行以下代码时出现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: obj() takes no parametrs
- python安装某模块时出现 TypeError: __call__() takes exactly
- python "TypeError: object() takes no parameters"
- python之TypeError: this constructor takes no arguments
- python:TypeError: this constructor takes no arguments解决方法
- python报错 TypeError: object() takes no parameters
- TypeError: object() takes no parameters
- TypeError: object() takes no parameters
- TypeError: object() takes no parameters
- TypeError: object() takes no parameters
- TypeError: object.__new__() takes no parameters
- TypeError: this constructor takes no arguments
- TypeError: this constructor takes no arguments
- TypeError: this constructor takes no arguments
- TypeError: object.__init__() takes no parameters
- TypeError: this constructor takes no arguments(Python 学习遇到的错误1)
- python 使用装饰器提示:TypeError: wrapper() takes no arguments (1 given)
- Python 3.5 + PyInstaller 3.2.1打包exe出错,TypeError: read() takes no keyword arguments
- 洛谷 P1605 迷宫
- 手机号码验证工具类
- 深入浅出Lucene Analyzer
- LightOJ 1149 Factors and Multiples【最小点覆盖】(这些图论专题的题目都好裸啊)
- Java编程思想重点笔记
- 运行python 时出现TypeError: obj() takes no parametrs
- spring中bean的scope属性
- SD卡工具类
- Java为什么计算时间从1970年1月1日开始
- select下拉框插件jquery.editable-select
- 铽罗机器人
- 尺寸相关工具类
- Lucene的分析过程
- javaEE