我在这里需要一个明确的解释.为什么以下代码有效?
foo1 = foo1[0] = [0]
Run Code Online (Sandbox Code Playgroud)
好的,我知道作业是从左到右完成的.
python如何理解foo1列表?
顺便说一句,我知道它foo1最终是[[...]]它的第一个元素.
首先,我运行以下代码,这真的很好:
class Monster:
def __init__(self):
self._can_do = []
print("created a monster")
super().__init__()
class Race(Monster):
""" all races must derive from this """
def __init__(self):
super().__init__()
print("created a race x")
class Human(Race):
def __init__(self):
super().__init__()
self._can_do.append("Do nothing special !")
print("created a human")
class Elf(Race):
def __init__(self):
super().__init__()
self._can_do.append("Avoid sleep")
print("created an elf")
class Class:
""" all classes must derive from this """
def __init__(self):
super().__init__()
print("created a class x")
class Fighter(Class):
def __init__(self):
super().__init__()
self._can_do.append("Hit hard")
print("created a fighter")
class Wizard(Class): …Run Code Online (Sandbox Code Playgroud)