Jun-30-2020, 03:50 PM
(This post was last modified: Jun-30-2020, 04:31 PM by Gribouillis.)
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:
Now the issue:
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?
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?