鱼C论坛

 找回密码
 立即注册
查看: 424|回复: 2

[技术交流] 构造函数出现BUG

[复制链接]
发表于 2025-4-17 15:34:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
class C:
    def _init_(self,x,y):
        self.x = x
        self.y = y
        def add(self):
            return self.x+self.y
        def mul(self):
            return self.x*self.y

        
KeyboardInterrupt
c=C(2,3)
Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    c=C(2,3)
TypeError: C() takes no arguments
C.add()
Traceback (most recent call last):
  File "<pyshell#28>", line 1, in <module>
    C.add()
AttributeError: type object 'C' has no attribute 'add'
c.__dict__
mappingproxy({'__module__': '__main__', '__firstlineno__': 1, '_init_': <function c._init_ at 0x000002012D5AA0C0>, '__static_attributes__': ('x', 'y'), '__dict__': <attribute '__dict__' of 'c' objects>, '__weakref__': <attribute '__weakref__' of 'c' objects>, '__doc__': None})
c.add()
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    c.add()
AttributeError: type object 'c' has no attribute 'add'
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2025-4-17 16:05:22 | 显示全部楼层
FishC AI 小助理解答很专业
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-6 04:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表