Operator Precedence/Boolean Logic

Gerald Britton gerald.britton at gmail.com
Sat Jul 16 09:58:31 EDT 2016


>Earlier you said:

>* > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a
*>* > graph..."
*>  >* I would make the empty graph (zero nodes) falsey, and non-empty
graphs (one
*>* or more nodes) truthy.
*>  >  >* > 2. Automata which in a way are special kinds of graphs
*>  >* As above.
*

>Now you say:

>* > If on the other hand you are giving that “return True”as a serious useful
*>* > definition?
*>  >* Sure. An automata is an object, and by default, all objects are
"something"
*>* and hence truthy. That's the "no-brainer" answer, it requires no
*>* justification at all. If you think the answer should be something else,
*>* *that* is what needs justification. Why shouldn't it be truthy?
*

>How do we put these two together>


easy peasy:  lists, tuples, dicts etc are also objects.  They define
their truthiness by the presence of members.  An empty list has a
boolean value of false.

for a custom object, you can accept the default boolean value of true
or override __bool__ so that it returns what you want.  So for a graph
G, I'd say if |V| = |E| = 0, G has a boolean value of false.

Maybe thusly?https://en.wikibooks.org/wiki/Sufism/Nasrudin#Of_any_two_options_choose_the_third

------------------------------


   - Previous message (by thread): Operator Precedence/Boolean Logic
   <https://mail.python.org/pipermail/python-list/2016-July/711778.html>
   - Next message (by thread): EuroPython 2016: Recruiting Offers
   <https://mail.python.org/pipermail/python-list/2016-July/711769.html>
   - *Messages sorted by:* [ date ]
   <https://mail.python.org/pipermail/python-list/2016-July/date.html#711777>
    [ thread ]
   <https://mail.python.org/pipermail/python-list/2016-July/thread.html#711777>
    [ subject ]
   <https://mail.python.org/pipermail/python-list/2016-July/subject.html#711777>
    [ author ]
   <https://mail.python.org/pipermail/python-list/2016-July/author.html#711777>

------------------------------
More information about the Python-list mailing list
<https://mail.python.org/mailman/listinfo/python-list>

-- 
Gerald Britton, MCSE-DP, MVP
LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton



More information about the Python-list mailing list