浏览代码

Fix explanation of range vs. xrange

xrange in Python 2 = range in Python 3.

Thanks to jemshad.ok@gmail.com for bringing this to my notice!
Swaroop C H 10 年之前
父节点
当前提交
f1efb2c08d
共有 1 个文件被更改,包括 3 次插入4 次删除
  1. 3 4
      control_flow.asciidoc

+ 3 - 4
control_flow.asciidoc

@@ -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