let's start by saying that your code will produce
so the code should be
The ideomatic code would not check the len, but will use the True value of non-empty list
IndentationError
. After fixing it, you will enter infinite loop, because you don't call the pop methodso the code should be
l = [10, 20, 30, 40] while len(l) != 0: print(l.pop())
list.pop()
method will return element from list and delete it from the list. Thus it will reduce the len of the list.The ideomatic code would not check the len, but will use the True value of non-empty list
spam = [10, 20, 30, 40] while spam: print(spam.pop())
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs