Skip to content

Commit

Permalink
Merge pull request #1541 from pallets/docs-pow-order
Browse files Browse the repository at this point in the history
document chained pow order
  • Loading branch information
davidism authored Nov 9, 2021
2 parents 99daa2a + 0d19990 commit 46f3a68
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1344,8 +1344,19 @@ but exists for completeness' sake. The following operators are supported:
``{{ '=' * 80 }}`` would print a bar of 80 equal signs.

``**``
Raise the left operand to the power of the right operand. ``{{ 2**3 }}``
would return ``8``.
Raise the left operand to the power of the right operand.
``{{ 2**3 }}`` would return ``8``.

Unlike Python, chained pow is evaluated left to right.
``{{ 3**3**3 }}`` is evaluated as ``(3**3)**3`` in Jinja, but would
be evaluated as ``3**(3**3)`` in Python. Use parentheses in Jinja
to be explicit about what order you want. It is usually preferable
to do extended math in Python and pass the results to ``render``
rather than doing it in the template.

This behavior may be changed in the future to match Python, if it's
possible to introduce an upgrade path.


Comparisons
~~~~~~~~~~~
Expand Down

0 comments on commit 46f3a68

Please sign in to comment.