+ 1

Output of the below code and why is that output printed?

squares=[0,1,4,8,64,81] print(squares[1:1:-1]) Can some please explain me What is the output of the code and why?

29th Apr 2020, 5:25 PM
pranavi Reddy
pranavi Reddy - avatar
4 Respostas
+ 3
Output is : [] an empty list. Beacause, in normal slicing [1:1] is also an empty one. Now you cannot reverse an empty list. So, -1 is useless here.
29th Apr 2020, 5:40 PM
M Tamim
M Tamim - avatar
+ 1
Thanks Abhay . next time sure i will post with an answer and ask for explanation.
29th Apr 2020, 7:24 PM
pranavi Reddy
pranavi Reddy - avatar
0
You should mention the output of the code and ask us why the output is this? there is code playground for it
29th Apr 2020, 5:28 PM
Abhay
Abhay - avatar
0
Thank you M Tamim for explaining the answer.
29th Apr 2020, 7:25 PM
pranavi Reddy
pranavi Reddy - avatar