The if
condition evaluates the "truthiness" of the object passed to it:
if object:
...
Is the same as:
if bool(object):
...
You'll see any string of length greater than 0 has a truthiness value of True
:
In [82]: bool('True')
Out[82]: True
In [83]: bool('False')
Out[83]: True
In essence, you'll need to change your if
to:
if string == 'True':
...
elif string == 'False':
When using strings in comparisons, use the ==
operator unless you know what you're doing.
In addition, it is useful to know about the truthiness of some other python builtins:
In [84]: bool(None)
Out[84]: False
In [85]: bool({})
Out[85]: False
In [86]: bool([])
Out[86]: False
In [87]: bool(['a'])
Out[87]: True