Skip to content

Commit 46f3a68

Browse files
authored
Merge pull request #1541 from pallets/docs-pow-order
document chained pow order
2 parents 99daa2a + 0d19990 commit 46f3a68

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

docs/templates.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,19 @@ but exists for completeness' sake. The following operators are supported:
13441344
``{{ '=' * 80 }}`` would print a bar of 80 equal signs.
13451345

13461346
``**``
1347-
Raise the left operand to the power of the right operand. ``{{ 2**3 }}``
1348-
would return ``8``.
1347+
Raise the left operand to the power of the right operand.
1348+
``{{ 2**3 }}`` would return ``8``.
1349+
1350+
Unlike Python, chained pow is evaluated left to right.
1351+
``{{ 3**3**3 }}`` is evaluated as ``(3**3)**3`` in Jinja, but would
1352+
be evaluated as ``3**(3**3)`` in Python. Use parentheses in Jinja
1353+
to be explicit about what order you want. It is usually preferable
1354+
to do extended math in Python and pass the results to ``render``
1355+
rather than doing it in the template.
1356+
1357+
This behavior may be changed in the future to match Python, if it's
1358+
possible to introduce an upgrade path.
1359+
13491360

13501361
Comparisons
13511362
~~~~~~~~~~~

0 commit comments

Comments
 (0)