diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index cbe780e075baf5..7381f8f031676a 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -245,6 +245,18 @@ and it's equivalent to:: Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets. +For multiple :keyword:`!if` statements, like this:: + + >>> [x for x in range(10) if x % 2 if x % 3] + [1, 5, 7] + +This example is equivalent to:: + + >>> [x for x in range(10) if x % 2 and x % 3] + [1, 5, 7] + +Note the second :keyword:`!if` is replaced by :keyword:`!and`. + If the expression is a tuple (e.g. the ``(x, y)`` in the previous example), it must be parenthesized. ::