Skip to content

Commit dc81120

Browse files
authored
Merge pull request taizilongxu#22 from Chaniel/master
difference between range and xrange
2 parents 4ba5aaa + 35653c5 commit dc81120

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- [27 read,readline和readlines](#27-readreadline和readlines)
3939
- [28 Python2和3的区别](#28-python2和3的区别)
4040
- [29 super.__init__()](#29-super-init)
41+
- [30 range-and-xrange](#30-range-and-xrange)
4142
- [操作系统](#操作系统)
4243
- [1 select,poll和epoll](#1-selectpoll和epoll)
4344
- [2 调度算法](#2-调度算法)
@@ -667,6 +668,16 @@ Note that the syntax changed in Python 3.0: you can just say super().__init__()
667668

668669
http://stackoverflow.com/questions/576169/understanding-python-super-with-init-methods
669670

671+
## 30 range and xrange
672+
都在循环时使用,xrange内存性能更好。
673+
for i in range(0, 20):
674+
for i in xrange(0, 20):
675+
What is the difference between range and xrange functions in Python 2.X?
676+
range creates a list, so if you do range(1, 10000000) it creates a list in memory with 9999999 elements.
677+
xrange is a sequence object that evaluates lazily.
678+
679+
http://stackoverflow.com/questions/94935/what-is-the-difference-between-range-and-xrange-functions-in-python-2-x
680+
670681
# 操作系统
671682

672683
## 1 select,poll和epoll

0 commit comments

Comments
 (0)