In Python, I'm trying to use nested for loops in my script to iterate over a list of object attributes. The iterated copy of the attribute resets during nested iteration. How can I modify the referenced object's attribute so that it doesn't reset?
class Player: def __init__(self, index, name, sex, bench) player1 = Player(1, "john", "male", True) player2 = Player(2, "bill" "male", True) roster = [player1, player2, player3] for x in roster x.bench = False How can I modify the object attribute (player1.bench) to match the iteration value (x.bench)?
没有评论:
发表评论