Take a look at this documentation page for Truth Value Testing in python. After reading, you should get a clear idea of your situation. Here is the relevant part for easy access.
5.1. Verification of the value of truth
Any object can be checked for true, for use in an if
or while
condition or as an operand of boolean operations below. The following values are considered false:
None
False
- zero of any number type, for example
0
, 0.0
, 0j
. - any empty sequence , for example
''
, ()
, []
. - any empty mapping, for example,
{}
. - instances of custom classes if the class defines a
__bool__()
or __len__()
when this method returns the integer 0 or bool
is False
.
All other values are considered true, so objects of many types are always true.
Read the first sentence again ( bold ) and pay attention to the bold parts in the fourth rule. This is relevant to your question.
So, according to the fourth rule, if your word_list
empty, the condition evaluates to False
, otherwise it will be True
.
I know that you trust the documents, but here is a piece of code that really checks the truth values for itself. (I know that you do not need to do something like this, but I always feel like seeing things with my own eyes)
def test_truth_value(arg): # ANY object can be evaluated for truth or false in python if arg: # or to be more verbose "if arg is True" print("'{}' is True".format(arg)) else: print("'{}' is False".format(arg)) class dummy_length_zero(): def __len__(self): return 0 def __str__(self): return 'instance of class: "dummy_length_zero"' class dummy_bool_False(): def __bool__(self): return False def __str__(self): return 'instance of class: "dummy_bool_False"' obj_dummy_0 = dummy_length_zero() obj_dummy_false = dummy_bool_False() args = [None, False, 0, 0.0, 0j, '', (), [], {}, obj_dummy_0, obj_dummy_false] for arg in args: test_truth_value(arg)
And finally, to check this last statement, so objects of many types are always true, just remove the implementation of the __len__()
or __bool__()
method from the dummy_length_zero
or dummy_bool_False
respectively, and check the truth.