2. What is the output produced by the following code snippet ?
alst=[1,2,3,4,5,6,7,8,9)
print(alst[::3])
Answers
Answered by
2
Answer:
[1,4,7]
Explanation:
Here starting point and ending point are not given.
increment value is 3.
1 2 3 4 5 6 7 8 9
^ ^ ^
Answered by
0
Output:
[1, 4, 7]
Here, there is a list having name "alst" and values "1,2,3,4,5,6,7,8,9". Now in the print statement slicing is of the list is happening. In order to access a range of elements from a list, we need to slice a list. Slicing of list returns a new list from the existing list.
Syntax:
List [ Initial : End : IndexJump ]
Similar questions