当前位置:网站首页>错误记录: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的提示中是都有这两种的,而且问题还不好查找
边栏推荐
- [漏洞问题] log4j漏洞 关于2.17.0升级到2.18.0 方案
- 数组的一些方法
- MAML principle explanation and code implementation
- JVM调优实践
- Verilog“七宗罪”
- 数据库知识:SQLServer创建非sa用户笔记
- Activiti 工作流引擎 详解
- A semi-supervised Laplace skyhawk optimization depth nuclear extreme learning machine for classification
- 设置el-table自动向下滑动(不多解释,直接代码实现)
- Interpretation of EfficientNet: Composite scaling method of neural network (based on tf-Kersa reproduction code)
猜你喜欢
随机推荐
七夕专属程序员的浪漫
目标检测中的先验框(Anchor)
关于我写的循环遍历
如何用matlab做高精度计算?【第一辑】
自适应迁移学习核极限学习机用于预测
matlab封闭曲线拟合 (针对一些列离散点)
Database knowledge: SQLServer creates non-sa user notes
Detailed explanation of DenseNet and Keras reproduction code
VMD combined with ISSA to optimize LSSVM power prediction
Mac安装PHP开发环境
E-R图总结规范
Implementation of ICEEMDAN Decomposition Code in MATLAB
YOLOv3详解:从零开始搭建YOLOv3网络
A priori box (Anchor) in target detection
Faster - RCNN principle and repetition code
花了近70美元入手的学生版MATLAB体验到底如何?
Gramm Angle field GAF time-series data into the image and applied to the fault diagnosis
窥探晶体世界的奥秘 —— 230种空间群晶体结构模型全在这里
What is the connection between GRNN, RBF, PNN, KELM?
matlab科研绘图模板,直接奉上源代码!









