lundi 23 juillet 2018

Python: removing an item from a list in the if statement condition?

I have this code:

myList = [1, 2, 3, 4, 5]

if (myList.remove(4)):
    print "We removed 4, so this is true!"

print myList

When I run it, this is what I get:

[1, 2, 3, 5]

So it appears that the "4" was removed from the list as specified in the condition of the if statement, yet the if statement did not end up being "True" since the print statement did not print to the console. Why is it that the if statement is false?

Aucun commentaire:

Enregistrer un commentaire