Question-128: 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]
- Get all Questions and Answer from here
- You need to have paid subscription to access all questions
- Thanks for considering Python Certification Material
Answer: D
Exp:
Slice using -ve index example.
- -1 represent last element in list.
- 1 is representing 2nd element in list.
- However, you are starting with last element. Hence, no element would be selected.
- Don’t consider list is cyclic and you start and end in cycle.
-
You can access to full explanation to question and answer from this page.