[Tutor] beginning to code

INADA Naoki songofacandy at gmail.com
Tue Sep 19 22:34:34 EDT 2017


>
>     >>> False > 1
>     False
>     >>> dir > 1
>     True
>     >>> isinstance < 100
>     False
>     >>> "" >= 10
>     True
>     >>> (1,) <= 500
>     False
>
> And down the rabbit hole we go!
>
> Now, not only do we have magic that implicitly casts all
> objects to booleans in conditional statements *AND* we have
> arbitrary Boolean values assigned to every Python object,
> but now, we discover that every Python object has been
> assigned an arbitrary rich comparison value as well! I
> assume the devs are using the boolean values 1 and 0 to make
> the comparison work??? But would someone be kind enough to
> chime in to confirm or deny my conjecture?
>

> Of course, allowing all objects to use the `==`, `!=` sugars
> makes perfect sense, but `<`, `>`, `<=`, `>=` are
> meaningless outside of numeric-ish types.
>
>
Now you know why Python 3 was born!
It's one of many pitfalls in Python 2 fixed in Python 3.
Welcome to Python 3 world.


> > I don't accept it because `if bool(x) == True` doesn't give
> > any information than `if x:`. Both mean just `if x is
> > truthy`.  No more information. Redundant code is just a
> > noise.
>
> So what about:
>
>     if bool(x):
>         # blah
>
>
I don't accept it too.  It only explains `if x is truthy value`, and it's
exactly same to `if x:`.
There are no additional information about what this code assumes.  bool()
is just noise.

-- 
Inada Naoki <songofacandy at gmail.com>



More information about the Python-list mailing list