Isečci sa negativnim pozicijama u Pythonu
U isečcima se možemo obraćati elementima i preko negativnih indeksa. U tom slučaju njihovo brojanje će ići od kraja sekvence. Hajde da napravimo isečak od trećeg do pretposlednjeg elementa:
pythontxt = '123456789'
res = txt[2:-1]
print(res) # ispisuje '345678'
Задание 1
Data je string:
pythontxt = '123456789'
Preuzmite iz njega sledeći isečak:
python'567'
Задание 2
Data je lista:
pythonlst = ['a', 'b', 'c', 'd', 'e', 'f']
Preuzmite iz nje sledeći isečak:
python['b', 'c', 'd']
Задание 3
Data je lista:
pythonlst = ['a', 'b', 'c', 'd', 'e', 'f']
Preuzmite iz nje sledeći isečak:
python['f']