Šķēle pozīciju diapazonā Python
Lai iegūtu šķēli, jānorāda tās pozīciju diapazons - no sākuma līdz beigām. Šajā gadījumā pa kreisi no kola norādām sākuma indeksu, bet pa labi - beigu indeksu:
pythontxt = 'abcde'
res = txt[1:3]
print(res) # izvadīs 'bc'
Задание 1
Dota virkne:
pythontxt = '12345'
Iegūstiet šķēli no visiem tās simboliem, izņemot pirmo un pēdējo:
python'234'
Задание 2
Dots saraksts:
pythonlst = [1, 2, 3, 4, 5, 6, 7]
Iegūstiet no tā šādu šķēli:
python[1, 2, 3]
Задание 3
Dots saraksts:
pythonlst = [1, 2, 3, 4, 5, 6, 7]
Iegūstiet no tā šādu šķēli:
python[2, 3, 4, 5]
Задание 4
Dots saraksts:
pythonlst = [1, 2, 3, 4, 5, 6, 7]
Iegūstiet no tā šādu šķēli:
python[2, 3, 4, 5, 6]