一入python深似海--range()、list与for
2024-08-30 01:18:56
range使用方法
使用python的人都知道range()函数非常方便,今天再用到他的时候发现了非常多曾经看到过可是忘记的细节。
这里记录一下:
range ( 1 , 5 ) #代表从1到5(不包括5) [ 1 , 2 , 3 , 4 ] range ( 1 , 5 , 2 ) #代表从1到5,间隔2(不包括5) [ 1 , 3 ] range ( 5 ) #代表从0到5(不包括5) [ 0 , 1 , 2 , 3 , 4 ] |
再看看list的操作:
array = [ 1 , 2 , 5 , 3 , 6 , 8 , 4 ] #事实上这里的顺序标识是 [ 1 , 2 , 5 , 3 , 6 , 8 , 4 ] ( 0 。 1 , 2 。 3 , 4 , 5 , 6 ) ( - 7 , - 6 , - 5 , - 4 , - 3 , - 2 , - 1 ) array[ 0 :] #列出0以后的 [ 1 , 2 , 5 , 3 , 6 , 8 , 4 ] array[ 1 :] #列出1以后的 [ 2 , 5 , 3 , 6 , 8 , 4 ] array[: - 1 ] #列出-1之前的 [ 1 , 2 , 5 , 3 , 6 , 8 ] array[ 3 : - 3 ] #列出3到-3之间的 [ 3 ]
loop |
最新文章
- yii2 rbac-plus的使用
- 前后台数据传输两种方式:servlet、Controller
- activiti自定义流程之自定义表单(二):创建表单
- node系列4
- zabbix 添加自定义key
- 「技巧」如何将Sketch改为深色模式
- CF #552(div3)F 背包问题
- 扩展的GM命令
- Vue项目在真机测试
- 在vue配置sass
- 2017.7.12 Python的6种内建序列及操作
- es6(13)--Promise
- webpack原理与实战
- [Go] Returning Multiple Values from a Function in Go
- Android开发中无处不在的设计模式——动态代理模式
- Java——IO类,字符缓冲区
- Spring源码分析(十八)创建bean
- how to show video in website
- Spring工具类ToStringBuilder用法简介
- 关于reduce的使用方法