【发布时间】:2016-07-06 17:32:38
【问题描述】:
class Solution:
def display(self,head):
current = head
while current:
print(current.data,end=' ')
current = current.next
你好,我在理解上面的while循环时遇到了一些困难,AFAIK你需要有一个while循环的条件,所以:
while (stuff) == True:
但是上面的代码有:
while current:
这是否与:
while current == head:
谢谢
【问题讨论】:
-
您似乎对while循环上方语句的含义感到困惑。它与循环无关或它是有条件的。相反,它将变量
head复制到变量current。然后将电流转换为布尔值并检查它的“真实性”,如下面的Mariusz Jamro 的answer 解释的那样。
标签: python loops while-loop