TypeError: Person() takes no arguments
定义和使用python类定义的时候报错如题中的错误,具体代码如下:
class Person:def _init_(self,name,age):self.name=nameself.age=agep1=Person('mary',12)
print(p1.name)
print(p1.age)
运行报错结果如下:
Traceback (most recent call last):
File "c:\users\viriya\mu_code\20210908.py", line 14, in <module>
p1=Person('mary',12)
TypeError: Person() takes no arguments
那么怎么解决呢?仅需修改第2行的代码_为__就可以了:
class Person:def __init__(self,name,age):self.name=nameself.age=agep1=Person('mary',12)
print(p1.name)
print(p1.age)
运行结果:
mary
12
TypeError: Person() takes no arguments相关推荐
- python类takes no arguments_Python构造函数报错:TypeError: People() takes no arguments
养浩然之气,做博学之人 问题 类的构造函数使用时报错如下: Traceback (most recent call last): File "D:/PythonProjects/Demo/8 ...
- TypeError: Animal() takes no arguments
问题参考 Python中报错提示:TypeError: Student() takes no arguments 问题背景 在联系python经典面试题的时候,做到了解引用计数机制时,创建类报错 附上 ...
- TypeError: ToTensor() takes no arguments
代码如下: from torchvision import transforms from PIL import Image img_path = "dataset/train/ants/0 ...
- Python TypeError: cat() takes no arguments
Python TypeError: cat() takes no arguments 很少用class 结果今天一个简单的TypeError差点没弄疯 #!/uer/bin/env python3 c ...
- TypeError: FC() takes no arguments
错误总结 原代码 class FC:def init(self,in_num,out_num,lr=0.01):self._in_num=in_numself._out_num=out_numself ...
- TypeError: Student() takes no arguments
运行Python时报TypeError: Student() takes no arguments这个错误 检查在构造函数时,是不是 __init__写成了__int__ def __ini ...
- python类的学习TypeError: Dog() takes no arguments
在对python的类的学习中,出现以下报错 my_dog = Dog('oppo', 6) TypeError: Dog() takes no arguments 输入的代码如下: class Dog ...
- 解决报错TypeError: people() takes no arguments
在学习构造方法的过程中遇到报错TypeError: people() takes no arguments 看似没有问题,但是就是运行不出来, 原因居然是:构造函数 def __init__(self ...
- TypeError: ToTensor() takes no arguments报错显示
在执行语句时报错, 错误显示: 原因:ToTensor后未加(),并没有实现tensor转换
最新文章
- 非常强悍的 RabbitMQ 总结,写得真好!
- win7与linux共享文件夹共享,Ubuntu+Win7+Samba实现文件共享
- 《Effective C#》Item 21:用委托实现回调
- ASP.NET实现二维码(QRCode)的创建和读取
- 如何在vb.net中取得两时间的毫秒差_科技品牌软文营销如何写出一篇爆文?
- 动态规划——有趣的数(ccf)
- 使用sqlyog创建数据库
- 前端面试题汇总(css基础篇)
- SpringBoot-Feign
- sqlinesdata教程_oracle数据库中的表如何能够导入到mysql中?
- linux 配置ssh免密码登录脚本
- c++ 11 之lambda
- Flask: wsgi接口
- 20135202闫佳歆——信息安全系统设计基础第九周学习总结
- 磨皮,美白,搞笑图片处理
- python 三维地球_python的matplotlib的模拟太阳-地球-月亮运动
- Windows中Redis的下载安装与修改密码并启动
- Apsara Clouder基础技能认证-阿里巴巴编程规范考试真题
- 读书笔记:《黎明之街》
- C语言flag(0)