Just starting to get to know Python. Every Python expression is supposed to have a boolean value. I'm trying to verify it with simple statements, the results are a bit confusing. In principle this does not seem to have an easy logic to understand. There is something behind it that is lost to me. What could it be?
Python 3.8.0 (default, Oct 28 2019, 16:14:01)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
> foo = 1
> foo is True
False
> bar = True if foo else False
> print("{}".format(bar))
True
>
> foo = 0
> foo is True
False
> bar = True if foo else False
> print("{}".format(bar))
False
> foo = '1'
> foo is True
False
> bar = True if foo else False
> print("{}".format(bar))
True
>
> foo = '0'
> foo is True
False
> bar = True if foo else False
> print("{}".format(bar))
True