+ 1

Can anyone tell the reason of the output

t=[1,2,4,3] t[1:-1]

5th May 2020, 7:49 AM
《A$# ☆ $ING#》
《A$# ☆ $ING#》 - avatar
2 ответов
+ 1
Here is the explanation : t = [1,2,4,3] print(t[1:-1]) # [2,4] The output is [2,4]. Because '-1' means till the last element. And '1' means from the first element. So '1:-1' means between first element to last element. The first element is 1 and the last element is 3. We have 2,4 between them. Therefore the answer is [2,4]. Again consider this : print(t[:-1]) # [1,2,4] print(t[1:]) # [2,4,3]
5th May 2020, 8:06 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
Thanks for answering 🙏
5th May 2020, 8:08 AM
《A$# ☆ $ING#》
《A$# ☆ $ING#》 - avatar