Sampling step for slicing in Python
If we need to select elements with a certain step, then we should specify a number in the third parameter of the slice. Let's select every second character except the first and last:
pythontxt = '123456789'
res = txt[1:9:2]
print(res) # '2468'
Задание 1
Given a string:
pythontxt = '123456789'
Get a slice of all its characters at odd positions:
python'13579'
Задание 2
The following code is given:
pythontxt = '123456789'
res = txt[1:-1:2]
print(res)
Write what is output to the console.
Задание 3
Given a list:
pythonlst = ['a', 'b', 'c', 'd', 'e']
Get the following slice from it:
python['a', 'd']