Multiple distinct objects: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Link to other example) |
|||
Line 36: | Line 36: | ||
which is incorrect since <code>Foo()</code> is only evaluated once. A common correct version is: |
which is incorrect since <code>Foo()</code> is only evaluated once. A common correct version is: |
||
<code python>[Foo() for i in xrange(n)]</code> |
<code python>[Foo() for i in xrange(n)]</code> |
||
which evaluates <tt>Foo()</tt> <var>n</var> times and collects each result in a list. |
which evaluates <tt>Foo()</tt> <var>n</var> times and collects each result in a list. This last form is also discussed [[Two-dimensional_array_(runtime)#Python|here]], on the correct construction of a two dimensional array. |