filmov
tv
Python Slices - Slice Lists and Strings (Extract Elements from Lists and Strings)

Показать описание
In this tutorial, we will go over how to use python slices (slice lists and strings in python). Think of a slice as something that allows you to take a slice out of a sequence of data such as a string or a list (extract certain elements from these lists and strings). Python slices can be useful for stripping out specific values from lists or extracting a substring. Python slices have some syntax tricks that allow you to start at the beginning without specifying the number and the same goes for the end, reverse a list or string, copy a list or string, and increment (step) a list or string which will skip the specified elements.
If you specify a specific end number, the slice will go up to but not include that element. If you specify a specific start number that element is included.
The python slice function has 3 parameters: slice(start, stop, step).
start - An integer number specifying at which position to start the slicing. Default is 0
end - An integer number specifying at which position to end the slicing
step - An integer number specifying the step of the slicing. Default is 1
If you specify a specific end number, the slice will go up to but not include that element. If you specify a specific start number that element is included.
The python slice function has 3 parameters: slice(start, stop, step).
start - An integer number specifying at which position to start the slicing. Default is 0
end - An integer number specifying at which position to end the slicing
step - An integer number specifying the step of the slicing. Default is 1