0
arr=[1,2,3,4,5,6] . print(arr[1:3] [2:5])
Please explain this to me
4 Respostas
+ 1
Actually your arr list is one dimension only and in print statement you are trying to getting input from 2d dimension arr but your arr is one dimension so that's why which gives you empty list.
#Output=[ ]
+ 1
Seb TheS i know list is in the code not a 2d but Prajwal Sharma try to retrieve the numbers from a 2d list which is actually a one dimension so that's why he getting [ ] as output.
0
Let's break print(arr[1:3] [2:5]) in parts:
arr = [1, 2, 3, 4, 5, 6]
a = arr[1:3]
b = a[2:5]
print(b)
a will get assigned the value arr[1:3], which evaluates to [2, 3], thus a = [2, 3].
Then b will get assigned the value a[2:5], but because [2, 3] has no values between indices 2 and 5, thus a[2:5] will evaluate to [ ] (empty string), and b = [ ].
Then b was printed, and an empty list was displayed.
0
Maninder $ingh That example has nothing to do with 2D arrays.