a=["four", "score", "and", "seven", "years"][[0,2,3][1]]
print(a)
output is : and
What is the main logic of this expression ?
a=["four", "score", "and", "seven", "years"][[0,2,3][1]]
print(a)
output is : and
What is the main logic of this expression ?
You need to read such expressions from the inside out. Let's start with the original:
a = ["four", "score", "and", "seven", "years"][[0,2,3][1]]
[0,2,3]
is a list, so you can access its elements with the []
operator. Since lists are zero-based, index 1
is the second item, which is 2
:
a = ["four", "score", "and", "seven", "years"][2]
Here, again, we're accessing a list element by its index. 2
refers to the third element, which is "and"
.
[0,2,3][1]
gives 2
which goes into ["four", "score", "and", "seven", "years"][2]
which in turn returns and
.