定义和使用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相关推荐

  1. python类takes no arguments_Python构造函数报错:TypeError: People() takes no arguments

    养浩然之气,做博学之人 问题 类的构造函数使用时报错如下: Traceback (most recent call last): File "D:/PythonProjects/Demo/8 ...

  2. TypeError: Animal() takes no arguments

    问题参考 Python中报错提示:TypeError: Student() takes no arguments 问题背景 在联系python经典面试题的时候,做到了解引用计数机制时,创建类报错 附上 ...

  3. TypeError: ToTensor() takes no arguments

    代码如下: from torchvision import transforms from PIL import Image img_path = "dataset/train/ants/0 ...

  4. Python TypeError: cat() takes no arguments

    Python TypeError: cat() takes no arguments 很少用class 结果今天一个简单的TypeError差点没弄疯 #!/uer/bin/env python3 c ...

  5. 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 ...

  6. TypeError: Student() takes no arguments

    运行Python时报TypeError: Student() takes no arguments这个错误 检查在构造函数时,是不是      __init__写成了__int__ def __ini ...

  7. python类的学习TypeError: Dog() takes no arguments

    在对python的类的学习中,出现以下报错 my_dog = Dog('oppo', 6) TypeError: Dog() takes no arguments 输入的代码如下: class Dog ...

  8. 解决报错TypeError: people() takes no arguments

    在学习构造方法的过程中遇到报错TypeError: people() takes no arguments 看似没有问题,但是就是运行不出来, 原因居然是:构造函数 def __init__(self ...

  9. TypeError: ToTensor() takes no arguments报错显示

    在执行语句时报错, 错误显示: 原因:ToTensor后未加(),并没有实现tensor转换

最新文章

  1. 非常强悍的 RabbitMQ 总结,写得真好!
  2. win7与linux共享文件夹共享,Ubuntu+Win7+Samba实现文件共享
  3. 《Effective C#》Item 21:用委托实现回调
  4. ASP.NET实现二维码(QRCode)的创建和读取
  5. 如何在vb.net中取得两时间的毫秒差_科技品牌软文营销如何写出一篇爆文?
  6. 动态规划——有趣的数(ccf)
  7. 使用sqlyog创建数据库
  8. 前端面试题汇总(css基础篇)
  9. SpringBoot-Feign
  10. sqlinesdata教程_oracle数据库中的表如何能够导入到mysql中?
  11. linux 配置ssh免密码登录脚本
  12. c++ 11 之lambda
  13. Flask: wsgi接口
  14. 20135202闫佳歆——信息安全系统设计基础第九周学习总结
  15. 磨皮,美白,搞笑图片处理
  16. python 三维地球_python的matplotlib的模拟太阳-地球-月亮运动
  17. Windows中Redis的下载安装与修改密码并启动
  18. Apsara Clouder基础技能认证-阿里巴巴编程规范考试真题
  19. 读书笔记:《黎明之街》
  20. C语言flag(0)

热门文章

  1. js获取传统节假日_vue js moment.js 过滤了双休日和法定节假日
  2. java中封装类Feild和使用setter和getter方法访问封装的类Feild
  3. jsp:使用jsp完成数据的分页显示
  4. 使用动态规划算法需要满足的必要条件:优化原则
  5. 史上最全数据库笔记(上)
  6. Eclipse中没有Servers或Dynamic Web Project的解决方案
  7. 游戏3D建模入门,有哪些建模软件可以选择?
  8. dva model数据管理
  9. Unity 游戏多语言解决方案和字体错误解决方法的想法
  10. 快排C语言三种实现方法(大同小异)