class Dog:
"""一次模拟小狗的简单尝试"""
def __init__(self,name,age):
"""初始化属性"""
self.name = name
self.age = age
self.p = 3
def a(self,c):
"""将p设置成指定增加的值"""
self.p += c(self前为什么不能加return,而下面的方法却可以)
def sit(self):
"""模拟小狗被命令时蹲下"""
return(self.name.title() + " is now sitting.")(此处用print()取代return,结果为什么会出现none)
my_dog = Dog('小白',10)
my_dog.a(2)
print(my_dog.p)
print(my_dog.sit())
皈依舞
相关分类