if L=[21,32,43,45,34,34,45] then
print (L[-4:-2]) will print:
Answers
Answered by
1
Output will be :
[45,34]
Answered by
1
Answer:
Given list,
>> L = [21, 32, 43, 45, 34, 34, 45]
>> print(L{-4:-2])
> [45, 34]
Explanation:
Python supports negative indexing. Let us write the elements of the list with their index (negative index).
From the table,
>> L[-1] = 45, L[-2] = 34 and so on.
So, L[-4 : -2] returns the elements of the list in the index range -4 to -3 (-2 is excluded). Step value is not mentioned. So, by default, step value = 1
Elements of the list in this range are - 45 and 34. So,
>> L[-4 : -2] = [45, 34]
Refer to the attachment.
•••♪
Attachments:
Similar questions