小编ers*_*ski的帖子

为什么 super().__init__ 没有自引用?

为什么我们使用的时候不需要自引用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)

python oop super python-3.x

3
推荐指数
1
解决办法
922
查看次数

当我们在while循环中给出两个比较运算符时,python如何理解?

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<5i<6,但是它在内部是如何工作的,程序如何理解i<5属于list1i<6属于list2?当我改变了while循环while i<6:,我得到IndexError: list index out of range

python python-3.x

2
推荐指数
1
解决办法
61
查看次数

标签 统计

python ×2

python-3.x ×2

oop ×1

super ×1