代码如下:

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

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐