[Solved] Explain the output of this code with nested ranges


>>> X = range(4, 7)  # List of number from 4 to 6
>>> Y = range(2)     # List of number from 0 to 1
>>> X
[4, 5, 6]
>>> Y
[0, 1]
>>> X[2] = Y         # Stored 'Y' at X[2] in place of '6'
                     # X[2]  is referencing Y  
>>> X
[4, 5, [0, 1]]
>>> print X[2][0]    # '0'th index of X[2] i.e Y[0] 
0
>>> print X[2][1]    # '1'th index of X[2] i.e Y[1]
1
>>> X[2][0] = 9      # Set '0'th index of X[2] i.e Y[0] as 9
>>> Y[0]
9
>>> Y
[9, 1]
>>> X
[4, 5, [9, 1]]

Now coming to your another question related to negative index. -i as index represnt ith element from the last. For example:

>>> X = range(4, 7)
>>> X
[4, 5, 6]
>>> X[-1]    # 1st element from last
6
>>> X[-3]    # 3rd element from last
4

1

solved Explain the output of this code with nested ranges