[Tutor] beginning to code

Chris Angelico rosuav at gmail.com
Mon Sep 18 08:58:22 EDT 2017


On Mon, Sep 18, 2017 at 10:42 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
>     (2) Python is, in essence, converting the source code
>     syntax of:
>
>         if someObject:
>
>     to:
>
>         if BOOLEAN_VALUE_OF_SOMEOBJECT:
>
>     Which, although the result of such a conversion (a
>     Boolean) will be perfectly symmetrical with formal logic
>     statements, the conversion is not obvious, because it
>     happens behind the curtains.

What a surprise. In the context of a statement that has exactly two
possible courses of action (either you go into the 'if' block, or you
go into the 'else' block (if any)), you use the boolean value of an
object. What part of this is not obvious?

Do you prefer languages that:

1) Require the use of an actual Boolean type? You still don't have to
compare the bool against True - "if bool(some_object)" would work.
2) Have no data types, but require that you use "1" or "0" (the
strings) to represent true and false?
3) Treat any nonzero value as false, and zero as true?

All of those exist. Are they somehow intrinsically better than the
Python model? Are they "more explicit"?

ChrisA



More information about the Python-list mailing list