First of all - your code will indeed raise an error because there is missing closing
now, look at
]
:-)now, look at
a = [3, 1, -2] print(a[a[-1]])
a[-1]
will return -2
, so this is equivalent to print(a[-2])
. and a[-2]
is 1
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs