赞
踩
range(stop) | 创建一个[0,stop)之间的整数序列,步长为1 |
---|---|
range(start,stop) | 创建一个[start,stop)之间的整数序列,步长为1 |
range(start,stop,step) | 创建一个[start,stop)之间的整数序列,步长为step |
a = range(1,5)
print(a) #range(1,5)
print(list(a)) #[1,2,3,4]
'''
for 自定义的变量 in 可迭代对象:
循环体
'''
#读出迭代器——字符串中的内容
for item in 'python':
print(item)
#读出迭代器——序列中的内容
for i in range(5):
print(i)
#仅作为循环而无需访问自定义变量,可以简单定义为_
for _ in range(5):
print('python')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。