python return 问题

为什么这样print(cat3+cats) 结果是None,但把 return other.append(self) 改成other.append(self)
return other 就可以正常返回,这两个有什么区别吗?

class Cat:
"""
这是一只猫的类
"""
def init(self,name,tail_length=10):
self.taillen=tail_length
self.name=name
print('我是一只猫,我叫 %s' % self.name)

def __add__(self, other):
    if isinstance(other,Cat):
        return [self,other]
    elif isinstance(other,list):
        return other.append(self)

cat1=Cat('crystal')
cat2=Cat('Sniper',15)
print(cat1+cat2)
cats=cat1+cat2
cat3=Cat('Alien')
print(cat3+cats)

def __add__(self, other):
    if isinstance(other, Cat):
        return [self, other]
    if isinstance(other, list):
        return other + [self]   
  1. list的append方法是对list尾部追加元素的操作,是没有返回值的, 但list已经改变。
  2. 满足第一个if后return,方法就会结束,后面不必用elif。
  3. 两个if都不满足,将return默认值None。

return 你的return 个值, append都没有返回值,你咋return

append是没有返回值的方法,但调用到它列表就会增加一项