Skip to content

Commit

Permalink
Slightly improve clarity of logical bool ops (#1938)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Dec 18, 2024
2 parents 619d8ee + 64a6bd1 commit 13c42b3
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1412,28 +1412,32 @@ Comparisons
Logic
~~~~~

For ``if`` statements, ``for`` filtering, and ``if`` expressions, it can be useful to
combine multiple expressions:
For ``if`` statements, ``for`` filtering, and ``if`` expressions, it can be
useful to combine multiple expressions.

``and``
Return true if the left and the right operand are true.
For ``x and y``, if ``x`` is false, then the value is ``x``, else ``y``. In
a boolean context, this will be treated as ``True`` if both operands are
truthy.

``or``
Return true if the left or the right operand are true.
For ``x or y``, if ``x`` is true, then the value is ``x``, else ``y``. In a
boolean context, this will be treated as ``True`` if at least one operand is
truthy.

``not``
negate a statement (see below).
For ``not x``, if ``x`` is false, then the value is ``True``, else
``False``.

``(expr)``
Parentheses group an expression.

.. admonition:: Note

The ``is`` and ``in`` operators support negation using an infix notation,
too: ``foo is not bar`` and ``foo not in bar`` instead of ``not foo is bar``
and ``not foo in bar``. All other expressions require a prefix notation:
Prefer negating ``is`` and ``in`` using their infix notation:
``foo is not bar`` instead of ``not foo is bar``; ``foo not in bar`` instead
of ``not foo in bar``. All other expressions require prefix notation:
``not (foo and bar).``

``(expr)``
Parentheses group an expression. This is used to change evaluation order, or
to make a long expression easier to read or less ambiguous.


Other Operators
~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 13c42b3

Please sign in to comment.