Skip to main contentSkip to solution

Find the output of the following code:-

result = 0
numList = [10,20,30]
numList.append(40)
result = result+numList.pop()
result = result+numList.pop()
print(result)

Solution

✅ Correct Option: 1

append(40) makes the list [10,20,30,40][10, 20, 30, 40]. pop() with no index removes and returns the last element.

The first pop() returns 4040, so result=0+40=40result = 0 + 40 = 40.

The second pop() returns 3030, so result=40+30=70result = 40 + 30 = \boxed{70}

print(result) shows a single number, not a pair like "40, 30", because result holds only the running sum.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question