0

I'm a beginner, I start the last 2 months to learn Python. This is my first post, I hope will be good. Can anyone help me and explain me this?

num = [1, 5, 6, 9, 12, 15, 18]
for x in num:
    if x > 0:
        num.remove(x)
print(num)

I thought that the result would be an empty list, but with this operation, it give me a list 'num' with [5, 9, 15]. And if I repeat with the same operation, and copy all the code, it'll be [9].

Why with this process I don't obtain an empty list?

Nicolò
  • 1
  • 1

0 Answers0