[New-bugs-announce] [issue38808] weird bug while using a for loop and array

Zach kuunka report at bugs.python.org
Fri Nov 15 02:06:57 EST 2019


New submission from Zach kuunka <zach.kunka at gmail.com>:

I haven't used this bug reporting thing before so sorry if I mess something up.

Anyway i'm not sure exactly what is causing the issue but the issue appears when you have a for loop looping through an array and you make a variable and set it to that array and append something to it. If you do the same thing with numbers it works as expected but if you do it with an array it for some reason doesn't get reset every iteration. Run this and you'll see what i'm talking about.

Arr = [1,2,3,4,5]
for num in Arr:
    Arr2 = Arr
    Arr2.append(1) #the 1 can be anything
    print(Arr2)

Also i'm interested to know why this happens, Thank You

----------
components: Library (Lib)
files: brokentest.py
messages: 356648
nosy: Zach kuunka
priority: normal
severity: normal
status: open
title: weird bug while using a for loop and array
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file48716/brokentest.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38808>
_______________________________________


More information about the New-bugs-announce mailing list