python对象不接受参数_python调用类提示object()不接受任何参数如如何解决
代码如下:class Dog():def init(self, name, age):self.name = nameself.age = agedef sit(self):print(self.name.title() + "is now sitting.")def roll_over(self):print(self.name.title() + "rolled over!")调用类my_do
代码如下:
class Dog():
def init(self, name, age):
self.name = name
self.age = age
def sit(self):
print(self.name.title() + "is now sitting.")
def roll_over(self):
print(self.name.title() + "rolled over!")
调用类
my_dog = Dog('willie' ,6)
my_dog.sit()
print("My dog's name is " + my_dog.self.name.title())
print("My dog is "+ str(my_dog.self.age)+ "years old!")
提示的错误如下:
TypeError Traceback (most recent call last)
in
----> 1 my_dog = Dog('willie' ,6)
2 my_dog.sit()
3 #print("My dog's name is " + my_dog.self.name.title())
4 #print("My dog is "+ str(my_dog.self.age)+ "years old!")
TypeError: object() takes no parameters
更多推荐
所有评论(0)