且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当 Python 只应追加到一个列表时,它追加到两个列表

更新时间:2022-12-09 21:02:56

在你所有的类中,你想像这样初始化实例变量:

In all of your classes, you want to initialize instance variables like this:

def __init__(self):
    self.participants = []
    self.teams = []
    self.attacked = []
    self.fighting = 0

这样,它们对于每个战斗、参与者、团队都是独立的,而不是为所有战斗、参与者或团队共享.

That way, they are separate for each fight, participant, team instead of shared for all fights, participants, or teams.