class Solution:
def display(self,head):
current = head
while current:
print(current.data,end=' ')
current = current.next
Hello, I am having some difficulties understanding the above while loop, AFAIK you need to have a condition with a while loop, so:
while (stuff) == True:
But the above code has:
while current:
Is this the same as:
while current == head:
Thanks
The while current: syntax literally means while bool(current) == True:. The value will be converted to bool first and than compared to True. In python everyting converted to bool is True unless it's None, False, zero or an empty collection.
See the truth value testing section for reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With