Python Forum
[HELP] Function that changes its entrances
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] Function that changes its entrances
#1
Hello everyone,

I struggle with a python code. I found the problem and reproduced the condition of its occurence in the following lines:

def PLS(A):
    B = A
    B[0] = B[2]
    return(B)
    
A = [1,2,3]
D = PLS(A)
print(A)
Compiling those few lines, I expect D to be [2,3,2] and A to be [1,2,3].
Yet I get D = A = [2,3,2]

Why does the code modify the A list?
And how can I stop it from doing so?

I'm really thankful for any help, I've been stuck for a while on that :D
Reply


Messages In This Thread
[HELP] Function that changes its entrances - by Liquid - Aug-07-2020, 08:14 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020