I would expect an empty list to value test as False, but I’m a bit confused why a reference for a list containing an object reports as False also when value tested as in the following example:
>>> weapon = []
>>> weapon == True
False
>>> weapon.append("sword")
>>> weapon == True
False
>>> weapon
['sword']
If weapon = [] is False, why would weapon = ['sword'] also be False? According to docs http://docs.python.org/release/2.4.4/lib/truth.html, it should be True. What am I missing in my understanding of this?
You need to use
bool()if you want to compare it directlyWhen you test a condition using
iforwhile, the conversion toboolis done implicitly