function definition:
def enumerate (sequence, start=0):
n = Start
For Elem in sequence:
Yield N, Elem
n + = 1
Examples of functions:
>>> seasons = [' Spring ', ' Summer ', ' Fall ', ' Winter ']>>> list (enumerate (seasons)) [(0, ' Spring '), (1, ' Summer '), (2, ' Fall '), (3, ' Winter ')]>>> list (Enumerate (seasons, Start=1)) [(1, ' Spring '), (2, ' Summer '), (3, ' Fa ll '), (4, ' Winter ')]
Usage Note: Enumerate (list,start=n) generates a list of tokens, and the starting value of the subscript is determined by N, incrementing
range(stop)
range(start, stop[, step])
xrange(stop)
xrange(start, stop[, step])
Start: Start range (incl.)
Stop: End range (not included)
Step: Each increment range
Cases:
>>> range [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> range (1, one) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> R Ange (0, 5) [0, 5, ten,, 25]>>> range (0,, 3) [0, 3, 6, 9]>>> range (0,-10,-1) [0,-1,-2,-3, -4, -5,-6,-7,-8, -9]>>> range (0) []>>> range (1, 0) []
the difference between range and xrange:
The range in Python2 is created with the values listed in memory, and Xrange is only created in memory when used, so xrange performance is higher than range,
The xrange is removed from the Pyhton3, the range is preserved, and the range in Python3 is equivalent to xrange in Python2
Both have the same usage
This article is from the "Xiaoice" blog, be sure to keep this source http://wbb827.blog.51cto.com/6948425/1932986
Python Development (Basic): Common functions