|
@@ -161,10 +161,9 @@ the first number and up to the second number. For example, `range(1,5)` gives th
|
|
|
that becomes the step count. For example, `range(1,5,2)` gives `[1,3]`. Remember that the range
|
|
|
extends *up to* the second number i.e. it does *not* include the second number.
|
|
|
|
|
|
-Note that `range()` generates a sequence of numbers, but it will generate only one number at a
|
|
|
-time, when the for loop requests for the next item. If you want to see the full sequence of numbers
|
|
|
-immediately, use `list(range())`. Lists are explained in the <<data_structures,data structures
|
|
|
-chapter>>.
|
|
|
+Note that `range()` generates a sequence of numbers all at once, so this is safe to use only for
|
|
|
+small ranges. If you want a long range but generated only one number at a time, then use
|
|
|
+`xrange()`. Lists are explained in the <<data_structures,data structures chapter>>.
|
|
|
|
|
|
The `for` loop then iterates over this range - `for i in range(1,5)` is equivalent to `for i in [1,
|
|
|
2, 3, 4]` which is like assigning each number (or object) in the sequence to i, one at a time, and
|