| 1 | initial version |
Note that you can use (1 .. 20) to iterate through the integers from 1 to 20,
without constructing the list of these integers, as [1 .. 20] does.
To obtain an iterator of squares:
sage: (k^2 for k in (1 .. 20))
To obtain the list of squares:
sage: [k^2 for k in (1 .. 20)]
To obtain the sum of squares:
sage: sum(k^2 for k in (1 .. 20))
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.