0

suppose we have python list

a=[1,2,3]
print(a[0]) will output 1
print(a[0:3]) will output [1,2,3]
print(a[4]) will output **IndexError: list index out of range**

But

print(a[0:4]) will output [1,2,3]

Why I am not getting error of IndexError: list index out of range this time? Also same for

a[3:4] i will get empty [] but not the error

0 Answers0