0
Why python program give output :3 to print([1,2,3,4][1:3][1]) this program
6 Answers
+ 7
Did u mean 3?
First of all [1,2,3,4][1:3] will give the output of [2,3] which it means it taken the numbers in the 1st and 2nd index of the list (start from index 0).
The the lines will become [2,3][1] which takes 1st index of numbers in the list (start from 0), which is 1
+ 2
Henil Parakhiya
List= [1,2,3,4]
Index [0,1,2,3]
print([1,2,3,4][1:3]) #o/p:- [2,3]
[1:3] select the list item starting from index 1 to 2
print([2,3][1]) #o/p:- [3]
+ 2
[1:3] returns a list with element 2,3 and so [1] returns 3
+ 1
Basically your program is doing this:
[1, 2, 3, 4] [1, 3] = [2, 3]
[2, 3] [1] = 3
print(3)
Have a nice day đ§đźââď¸đ§đźââď¸đ§đźââď¸
+ 1
Thank you all for answering my question.You all guys are so kind.