slice python 2 code example
Example 1: python slice
arr = ['a', 'b', 'c', 'd', 'e']
arr[2:] => ['c', 'd', 'e']
arr[:4] => ['a', 'b', 'c', 'd']
arr[2:4] => ['c', 'd']
arr[0:5:2] => ['a', 'c', 'e']
arr[:] => makes copy of arr
Example 2: python slice operator
string = 'string_text'
beginning = 0
end = len(string)
step = 1
new_string = string[beginning:end:step]
a = 0
b = 3
c = 1
new_string = string[a:b:c]
a = 2
b = len(string) - 2
c = 1
new_string = string[a:b:c]
Example 3: string slicing in python 3 arguments
>>> range(10)[::2]
[0, 2, 4, 6, 8]