+ 3

What is slicing of data in lists ?

6th Oct 2025, 3:10 PM
Akash Pokhrel
Akash Pokhrel - avatar
6 Respuestas
+ 7
Slicing, as it suggests, a slice of something. In other word, a portion of something. Real world example, a slice of a pizza. Python list: my_list = [1, 2, 3, 4, 5] If you want to get [2, 3] from it, you "slice" it with my_list[1:3]. print(my_list[1:3]) gives you [2, 3], "a slice of the list."
6th Oct 2025, 3:36 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 7
Akash Pokhrel , > slicing is explained in the `python developer` tutorial in the module `working with lists`. may be you can re-read this module. > slicing can look a bit confusing, especially when *negative slicing* or a mix of *negative and positive* slicing is used. > it is recommended to practice this repeatedly because slicing can be very helpful. it can be applied to lists, strings, tuples,... and is also available in some other programming languages.
6th Oct 2025, 3:41 PM
Lothar
Lothar - avatar
+ 2
Slicing is slicing a list elements according to indexing star end step
6th Oct 2025, 4:36 PM
Annu Yadav
Annu Yadav - avatar
+ 2
List slicing, also known as list slicing in Python programming, is a technique for extracting a portion or subset of a list by specifying a start and end index to create a new, smaller list. This process is particularly useful for breaking large data sets into smaller chunks for testing, debugging, or improving data processing efficiency, as the smaller data size reduces execution time and memory requirements.
7th Oct 2025, 9:58 PM
DHIMAN
DHIMAN - avatar
+ 1
slicing a list is like cutting the extra edges of it to get only your needed piece of data. When accessing the items in a list, you can either get a single item as it is or more than one at the time as another list In general in python the slicing syntax for a list is like: list[<first>:<last>:<step>] or list[<first>:<last>] or list[<first>] -> gets a single item Note: <first> should be replaced with the index of the first item to start with <last> should be replaced with the index of the last item (this item will be excluded from the resulting list) <step> (ignored in most cases) it can be either positive or negative and it tells the direction of your resulting list and what items to include, some known example to reverse a list/str: list[::-1] (here the <first> and <last> indexes are not provided and left empty which makes it use their default values: the full list with no cutting) <first> and <last> can also be either positive (counting from the beginning) or negative (counting from the end)
12th Oct 2025, 4:12 PM
Sousou
Sousou - avatar