2018年05月23日14:42:32
>>> range(1, 101)
[1, 2, 3, ..., 100]
请利用切片,取出:
- 前10个数;
- 3的倍数;
- 不大于50的5的倍数。
>>> list(range(1, 101))[:10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> list(range(1, 101))[2::3]
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]
>>> list(range(1, 101))[4:51:5]
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
大家如若有兴趣,欢迎朋友,可以加交流群:692-858-412一起学习
喜欢我的文章可以关注我哦,别忘了点个喜欢!
网友评论
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> range(1,101)[::3]
[1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100]
>>> range(1,101)[2::3]
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]
>>> range(1,101)[4:50:5]
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
在命令行调试直接贴过来的 那个忽略:D