为什么我们使用的时候不需要自引用super().__init__?(比如下面第9行)
class labourers():
def __init__(self,name,department,salary):
self.name = name
self.department = department
self.salary = salary
class managers(labourers):
def __init__(self,name,department,salary,numberofpeople):
super().__init__(name,department,salary)
self.numberofpeople = numberofpeople
Run Code Online (Sandbox Code Playgroud) list1 = [1,2,3,4,5]
list2 = [6,7,8,9,10,11]
new_list = list()
i = 0
while i<5 and i<6:
new_list.append((list1[i],list2[i]))
i += 1
print(new_list)
Run Code Online (Sandbox Code Playgroud)
该代码有效,输出为:
[(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)]
Run Code Online (Sandbox Code Playgroud)
然而,我只是想知道当我们在 while 循环中给出两个更大/更小的选项时 Python 是如何工作的。在上面的例子中,我已经定义了i<5和i<6,但是它在内部是如何工作的,程序如何理解i<5属于list1和i<6属于list2?当我改变了while循环while i<6:,我得到IndexError: list index out of range。