+ 1
The Output is [4,5], but why? đ€
arr=[1,2,3,4,5,6] print(arr[2:5][1:3]) Output [4,5]
3 Answers
+ 7
Once typo corrected to: print(arr[2:5][1:3])
You need to understand Python array slicing:
https://www.pythoncentral.io/how-to-slice-listsarrays-and-tuples-in-python/
array[start index:excluded end index]
arr[2:5] is tmp = [3,4,5]
and then, tmp[1:3] = [4,5]
+ 10
Yohann
isn't it "print(arr[2:5][1:3])" instead of "print(arr[2:5][1,3])"?
+ 1
Traceback (most recent call last):
File "..\Playground\", line 2, in <module>
print(arr[2:5][1,3])
TypeError: list indices must be integers or slices, not tuple
you are calling a tuple in another part of the archive, not the array that you have in the code that you wrote, right?