# Ranges[有序不变数字序列]
def ranges():
# 创建
ranges = range(10)
ls = list(ranges)# <class 'list'>: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
ranges = range(1, 10)
ls = list(ranges)# <class 'list'>: [1, 2, 3, 4, 5, 6, 7, 8, 9]
ranges = range(1, -10, -2) # (开始, 停止, 步骤)
ls = list(ranges) # <class 'list'>: [1, -1, -3, -5, -7, -9]
# 获取
ranges = range(10)
num = ranges.index(5) # 5
num = ranges[5] # 5
r1 = ranges[:5] # range(0, 5)
ls = list(r1) # <class 'list'>: [0, 1, 2, 3, 4]
r2 = ranges[1:5] # range(1, 5)
ls = list(r2) # <class 'list'>: [1, 2, 3, 4]
r3 = ranges[1:5:2] # range(1, 5, 2)
ls = list(r3) # <class 'list'>: [1, 3]
# 判断
boolean = 5 in ranges
boolean = 5 not in ranges
# 高级的用法
l4 = list(x**2 for x in range(1, 5)) #这样更快 <class 'list'>: [1, 4, 9, 16]
l5 = list(x+y for x in range(5) if x%2 == 0 for y in range(10) if y%2 ==1)
# <class 'list'>: [1, 3, 5, 7, 9, 3, 5, 7, 9, 11, 5, 7, 9, 11, 13]