当前位置:网站首页>错误记录:TypeError: object() takes no parameters
错误记录:TypeError: object() takes no parameters
2022-08-04 05:56:00 【LCY133】
一个很简单的定义类和进行实例化的例子
# 创建和使用类
class Dog1:
# 定义一个类
def __int__(self,name,age): # 注意,初始化时不要把init写成int,这样会导致在实例化时显示没有参数
self.name = name
self.age = age
print('init is running')
def sit(self):
print(self.name,'is now sitting')
def roll_over(self):
print(self.name,'is now rolling')
my_dog = Dog1('blue',10)
my_dog.sit()
在运行时出现问题:
Traceback (most recent call last):
File "E:/Python_code/0.review/lesson1/class_test.py", line 20, in <module>
my_dog = Dog1('blue',10)
TypeError: object() takes no parameters
其实问题的原因在于,写__init__方法时写成了__int__,在这里很容易写错的,因为pycharm的提示中是都有这两种的,而且问题还不好查找
边栏推荐
- 反射与枚举
- 格拉姆角场GAF将时序数据转换为图像并应用于故障诊断
- 原型图总结规范
- MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
- “需求370解决解决爬取章节之后主题讨论评论消失问题”工作总结
- this关键字,构造函数
- 【深度学习实践(二)】上手手写数字识别
- Network skills: teach you to install batteries on the router, you can still surf the Internet when the power is cut off!
- matlab的2DCNN、1DCNN、BP、SVM故障诊断与结果可视化
- MySQL内存淘汰策略
猜你喜欢

Database Skills: Organize SQL Server's Very Practical Scripts

idea使用@Autowired注解爆红原因及解决方法

自适应迁移学习核极限学习机用于预测

SENet detailed explanation and Keras reproduction code

目标检测中的IoU、GIoU、DIoU与CIoU

Detailed explanation of DenseNet and Keras reproduction code

Faster - RCNN principle and repetition code

MySQL面试题大全(陆续更新)

数据库:整理四个实用的SQLServer脚本函数

Database knowledge: SQLServer creates non-sa user notes
随机推荐
EfficientNet解读:神经网络的复合缩放方法(基于tf-Kersa复现代码)
Faster RCNN原理及复现代码
MySQL(4)
Microsoft computer butler 2.0 beta experience
YOLOv3详解:从零开始搭建YOLOv3网络
SystemVerilog-条件(三元)运算符
原型图总结规范
数据特征预处理——缺失值的查看方式及处理
对产品设计,架构设计的一点思考
90多款matlab工具箱打包放送
Centos通过Docker搭建MySQL的PXC集群
curl (7) Failed connect to localhost8080; Connection refused
matlab科研绘图模板,直接奉上源代码!
pycharm专业版使用
[漏洞问题] log4j漏洞 关于2.17.0升级到2.18.0 方案
NelSon:一款新的适配matlab编程语法的编程工具
matlab让我的旧手机起死回生
matlab封闭曲线拟合 (针对一些列离散点)
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法