在 Python 类中,我编写了以下方法:
class user():
address_list = []
def __init__(self):
self.address_list.append("a")
当我这样使用它时:
ur1 = user()
ur1.address_list.append("b")
ur2 = user()
ur2.address_list.append("c")
ur2.address_list.append("d")
print("user1's address: ", len(ur1.address_list))
print("user2's address: ", len(ur2.address_list))
输出是:
user1's address: 5
user2's address: 5
但我的期望是:
user1's address: 2 #a, b
user2's address: 3 #a,c,d
我的代码有什么问题?