You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Index error is thrown correctly in list[idx]. But, not in list.pop(idx). In Python, pop() also can have an index as an argument. Following is test code I tried:
def test_keycheck(idx):
print('in test_keycheck(), idx=', idx)
#__pragma__ ('keycheck') # to catch IndexError
stack= []
try:
content = stack.pop(idx)
except IndexError as e:
print('Caught IndexError')
raise e
except KeyError as e:
print('Caught KeyError')
raise e
except Error as e:
print('Caught Error')
raise e
print('content= ', content)
#__pragma__ ('nokeycheck')
def main():
test_keycheck(-1)
test_keycheck(0)
test_keycheck(1)
if __name__ == '__main__':
main()
result:
in test_keycheck(), idx= -1
content= None
in test_keycheck(), idx= 0
content= None
n test_keycheck(), idx= 1
content= None
IndexError is thrown in CPython.
Thanks
The text was updated successfully, but these errors were encountered:
Index error is thrown correctly in list[idx]. But, not in list.pop(idx). In Python, pop() also can have an index as an argument. Following is test code I tried:
result:
IndexError is thrown in CPython.
Thanks
The text was updated successfully, but these errors were encountered: