# !/usr/bin/env python3
# -*- coding:utf-8 -*-
class Dog:
def _init_(self,name):
self.name=name
def play(self):
print("汪汪汪!我是",self.name)
dog=Dog("旺财")
dog.play()
这段程序运行到dog=Dog("旺财")时总会出现
发生异常:Type Error
Dog() takes no arguments
File "F:\lianxi\7.2.6.py" ,line 11
in <module> dog=Dog("旺财")
Type Error: Dog() takes no arguments
是什么原因造成这样?怎么解决?
https://www.liaoxuefeng.com/wiki/1016959663602400/1017496031185408
仔细读高亮警告
Sign in to make a reply
众山小
# !/usr/bin/env python3
# -*- coding:utf-8 -*-
class Dog:
def _init_(self,name):
self.name=name
def play(self):
print("汪汪汪!我是",self.name)
dog=Dog("旺财")
dog.play()
这段程序运行到dog=Dog("旺财")时总会出现
发生异常:Type Error
Dog() takes no arguments
File "F:\lianxi\7.2.6.py" ,line 11
in <module> dog=Dog("旺财")
Type Error: Dog() takes no arguments
是什么原因造成这样?怎么解决?