python中list切片詳解
python中list切片詳解
語法:[start:stop:step]
step代表切片步長;切片區間為[start,stop),包含start但不包含stop
1.step > 0,從左往右切片
2.step <0,從右往左切片
3.start、stop、step 為空值時的理解:
start、stop預設為列表的頭和尾,並且根據step的正負進行顛倒;step的預設值為1
4.start、stop為負,無論step正負,start、stop代表的是列表從左到右的倒數第幾個元素
st = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’]
print(st[2:6:2])
print(st[6:2:-2])
print(st[::1])
print(st[::-1]) # 倒序輸出
print(st[-1])
輸出結果:
[‘c’, ‘e’]
[‘g’, ‘e’]
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’]
[‘g’, ‘f’, ‘e’, ‘d’, ‘c’, ‘b’, ‘a’]
g
相關文章
- Python中list的切片細節Python
- python切片詳解Python
- python 切片獲取list、tuple中的元素Python
- 詳解 go 的切片Go
- list中add、set方法詳解
- python列表(list)和元組(tuple)詳解Python
- python中的字串切片Python字串
- 切片底層陣列詳解陣列
- Java面試-List中的sort詳細解讀Java面試
- Go 切片詳解(理解是關鍵)Go
- Python3之字串str、列表list、元組tuple的切片操作Python字串
- C# List用法詳解C#
- python中dict詳解Python
- Golang切片和陣列底層詳解Golang陣列
- Python中的Super詳解Python
- 詳解Python中的程式Python
- Python中的列表詳解Python
- python字串切片Python字串
- Python 中的反轉字串:reversed()、切片等Python字串
- 在C++中實現Python的切片C++Python
- python中list有哪些方法Python
- Python中list的遍歷Python
- Python3中urlopen()詳解Python
- python 中model.py詳解Python
- Python中的函式詳解Python函式
- Python中的__new__()詳解Python
- Python中Numpy函式詳解Python函式
- Python中協程(coroutine)詳解Python
- python的特性 – 切片Python
- Python列表切片操作Python
- python切片處理Python
- PyThon numpy中array如何轉list?Python
- python中的list、tuple和dictionaryPython
- Java集合中List,Set以及Map等集合體系詳解(史上最全)Java
- RMAN的list和report命令詳解
- Python 中的魔術方法詳解Python
- python中setting.py詳解Python
- Python中的魔術方法詳解Python