Question-127: When you run below program, then what would be printed on console?
listA= [1,2,3,4,5]
listB=listA[1:-1]
print(listB)
- [1,2,3,4,5]
Answer: E
Exp:
Slice using -ve index.
- If you see -1 is equal to first element in list.
- However, as per slicing logic -1 position would not be included.
-
You can access to full explanation to question and answer from this page.