使用range函数生成数值列表
使用range函数打印1~5的数字
for i in range(1,6): print(i)
输出
1 2 3 4 5
利用range函数生成数值列表
>>> numbers = list(range(1,6)) >>> >>> type(numbers) <class 'list'> >>> >>> numbers [1, 2, 3, 4, 5]
指定数值列表步长
>>> numbers = list(range(1,11)) >>> >>> numbers [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> >>> del numbers >>> >>> numbers = list(range(1,11,2)) >>> >>> numbers [1, 3, 5, 7, 9] >>> >>> del numbers >>> >>> numbers = list(range(1,11,3)) >>> >>> numbers [1, 4, 7, 10]
数值列表的聚合函数计算
>>> numbers = list(range(1,11)) >>> >>> numbers [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> >>> min(numbers) 1 >>> >>> max(numbers) 10 >>> >>> sum(numbers) 55
===================来自一泽涟漪的博客,转载请标明出处 www.cnblogs.com/ilifeilong===================