python range( )函数,,v=range(n)


v=range(n),表示创建的范围是0-(n-1)

v=range(m,n,a),表示创建的范围为m-(n-1),步长为a

在python3中,序列刚创建时,每一个单个的值并没有在内存中存在,进行循环时才会在内存中一个一个创建,而在python2中,序列刚创建时就在内存中存在

0  2  4  6  8  [[email protected] test]# cat range.py v1=range(10)for item in v1:    print(item,end=‘  ‘)print(‘‘)v2=range(0,10,2)for item in v2:    print(item,end=‘  ‘)print(‘‘)[[email protected] test]# python range.py 0  1  2  3  4  5  6  7  8  9  0  2  4  6  8  

python range( )函数

评论关闭