Slicing a Range of Positions in Python
To get a slice, you need to specify a range of positions for it - from the beginning to the end. In this case, we set the initial index to the left of the colon, and the final index to the right:
pythontxt = 'abcde'
res = txt[1:3]
print(res) # 'bc'
Задание 1
Given a string:
pythontxt = '12345'
Get a slice of all its characters except the first and last:
python'234'
Задание 2
Given a list:
pythonlst = [1, 2, 3, 4, 5, 6, 7]
Get the following slice from it:
python[1, 2, 3]
Задание 3
Given a list:
pythonlst = [1, 2, 3, 4, 5, 6, 7]
Get the following slice from it:
python[2, 3, 4, 5]
Задание 4
Given a list:
pythonlst = [1, 2, 3, 4, 5, 6, 7]
Get the following slice from it:
python[2, 3, 4, 5, 6]