Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement list slicing in Python

Shulou Source: shulou.com Published: 2022-06-02 08:16:46 10月02日 Update

This article introduces how to achieve list slicing in Python. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Code implementation

Stus = ['Sun WuKong', 'Zhu Bajie', 'Sha Wujing', 'Tang Monk', 'Spider Fine', 'Baigujing'] print (stus [- 2]) print (STUS [1:]) print (stus [: 3]) print (stus [:]) print (stus) print (STUS [0: 5:3]) print (stus [::-1])

Code run output:

Spider essence

['Zhu Bajie', 'Sha Wujing', 'Tang Monk', 'Spider essence', 'White Bone essence']

['Sun WuKong', 'Zhu Bajie', 'Sha Wujing']

['Sun WuKong', 'Zhu Bajie', 'Sha Wujing', 'Tang Monk', 'Spider essence', 'White Bone essence']

['Sun WuKong', 'Zhu Bajie', 'Sha Wujing', 'Tang Monk', 'Spider essence', 'White Bone essence']

['Sun WuKong', 'Tang monk']

['Baigujing', 'Spider Jing', 'Tang Monk', 'Sha Wujing', 'Zhu Bajie', 'Sun WuKong']

On how to achieve list slicing in Python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Monk spider Tang monk Sun WuKong Zhu Bajie spider essence white bone essence code content more help good interest boy partner article knowledge article reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Redmi Shulou Technology Docker Huawei