Python Forum
pop recursive to other variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pop recursive to other variables
#1
Disclaimer: I am not a python guru, other languages quasi-guru.

This isn't making sense to me, either I'm not fully understanding the pop method or possibly I have discovered a glitch???

Example of the way I expect variables to function:
Python 3.8.2 (default, Apr 27 2020, 15:53:34) 
[GCC 9.3.0] on linux

>>> x=1
>>> y=2
>>> z=3
>>> print(x,y,z)
1 2 3
>>> y=x
>>> print(x,y,z)
1 1 3
>>> x=x+1
>>> print(x,y,z)
2 1 3
>>> 
Changing the variable X does not effect the variable Y in this example
Now the issue:

>>> color=['black','brown','green','yellow']
>>> print(color)
['black', 'brown', 'green', 'yellow']
>>> color2=color
>>> print(color,color2)
['black', 'brown', 'green', 'yellow'] ['black', 'brown', 'green', 'yellow']
>>> colorpop=color2.pop()
>>> print(color,color2,colorpop)
['black', 'brown', 'green'] ['black', 'brown', 'green'] yellow
>>> 
var color2 received the list from var color
var colorpop it the pop of var color2

but the pop of color2 recursively effects the var color as well

Why are both var color and color2 "popped"
Am I missing something here?
Reply


Messages In This Thread
pop recursive to other variables - by nieman050313 - Jun-30-2020, 03:50 PM
RE: pop recursive to other variables - by bowlofred - Jun-30-2020, 05:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,395 Jan-17-2021, 03:02 AM
Last Post: Jeremy7

Forum Jump:

User Panel Messages

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