- Hands-On Penetration Testing with Python
- Furqan Khan
- 292字
- 2021-07-02 14:13:50
Slicing the lists
Slicing is an operation that allows us to extract elements from sequences and lists. We can slice lists to extract portions that we might be interested in. It must be noted again that the indexes of slicing are 0-based and that the last index is always considered to be n-1, where n is the specified last index value. To slice the first five and last five elements from the list, we can perform the following operation:

Let's see some examples of list slicing and their results:
- To get the list from index 4 onwards, do the following:

- To get the list elements from the start up to index 4, do the following:

- To print the whole list with slicing, do the following:

- To print the list elements with a step size of 2, do the following:

- To print the reverse of the list, do the following:

- To print a portion of the list in reverse order, do the following:

- Add new elements to list-append(): The append() method is used to add elements to the list, and the elements to be added are given as an argument to the append() method. These elements to be added can be of any type. As well as being a number or a string, the element can be a list in itself:

We can see in the preceding example that we added three elements, 6, 7, and 8, to our original list using the append() method. Then, we actually added another list containing three characters that would be stored intact as a list inside the original list. These can be accessed by specifying the my_list[8] index. In the preceding example, the new list is added intact to the original list, but is not merged.
- Learn ECMAScript(Second Edition)
- Kibana Essentials
- Java高手真經(jīng)(高級(jí)編程卷):Java Web高級(jí)開(kāi)發(fā)技術(shù)
- 區(qū)塊鏈架構(gòu)與實(shí)現(xiàn):Cosmos詳解
- Programming ArcGIS 10.1 with Python Cookbook
- Python自然語(yǔ)言處理(微課版)
- 秒懂設(shè)計(jì)模式
- Windows Server 2012 Unified Remote Access Planning and Deployment
- 小程序,巧運(yùn)營(yíng):微信小程序運(yùn)營(yíng)招式大全
- Learning AWS
- Maker基地嘉年華:玩轉(zhuǎn)樂(lè)動(dòng)魔盒學(xué)Scratch
- 零代碼實(shí)戰(zhàn):企業(yè)級(jí)應(yīng)用搭建與案例詳解
- Distributed Computing in Java 9
- STM8實(shí)戰(zhàn)
- iOS開(kāi)發(fā)項(xiàng)目化入門教程