我不确定这段代码的输出是正确的还是错误的:
class F:
"""An abstract class"""
list_of_secrets = []
def __init__(self):
pass
def getSecret(self):
return self.list_of_secrets
class F_None(F):
pass
class F_Some(F):
def __init__(self):
self.list_of_secrets.append("secret value!")
x = F_Some()
print "x:",x.getSecret()
y = F_None()
print "y:",y.getSecret()
使用 python 2.7.3 的输出:
x: ['secret value!']
y: ['secret value!']
我认为它应该输出:
x: ['secret value!']
y: []
有什么想法吗?