[Python] Use pop function to catch a value and then add them

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I was using pop function to catch a value and then add them as below

    my_list = [1,2,3,4,5]
    a = my_list.pop(0)
    b = my_list.pop(0)
    c = a+b
    print(c)


    I was expecting the output as 2 but it shows it as 3. I tried capturing value at different position and add them but it always gave me a number higher then the actual answer

    like if POP position were 1 and 2 the addition should be 5 but it shows 6.

    Can someone help me with more clarity on this please?

    Continue reading...

Compartilhe esta Página