In this code below, a list
is set as a flag for while loop and then the author iterates by calling pop()
on the list, and this loop produces an output as long as the list is not empty.
unconfirmed_users = ['alice', 'brian', 'candace']
while unconfirmed_users:
current_user = unconfirmed_users.pop()
print("Verifying user: " + current_user.title())
confirmed_users.append(current_user)
Output:
Verifying user: Candace
Verifying user: Brian
Verifying user: Alice
I know that in programming languages, constants are treated as having boolean value True
. So, I concur that even objects are treated as constants in python, perhaps. However if that it the case, even an empty list is an object too and is constant. Why does that evaluate to False
?
ls = []
if(not ls):
print("empty list evaluates to False")
Output:
empty list evaluates to False