I am trying to learn Python and can't get my head around why this while loop I found breaks:
while string:
print("Test")
string = string[3:]
With for example
string = "123456789"
The output is:
Test
Test
Test
The way I understood the while function is, that it breaks only when the expression following the while command is False. But how can string = string[3:] be False, I mean it just changes string form being "123456789" to being "456789"?
Thanks for any tips!
"123456789", then it's"456789", then it's"789", and then it's"", which is consideredfalseand thewhileloop breaks.Falsy. freecodecamp.org/news/truthy-and-falsy-values-in-python