Linked Questions
67 questions linked to/from Are Python variables pointers? Or else, what are they?
7
votes
4
answers
1k
views
python byRef // copy [duplicate]
I am new to Python (and dont know much about programming anyway), but I remember reading that python generally does not copy values so any statement a = b makes b point to a. If I run
a = 1
b = a
a = ...
4
votes
4
answers
1k
views
Why is a variable not updating after changing its dependent variable? [duplicate]
I don't understand why the variable 'y' doesn't update when I change the x? (The 'y' variable is dependent on 'x' right?)
x = 5
y = x*2
print(x)
print(y)
x = 3
# Expect it to print '3' and '6' ...
5
votes
2
answers
306
views
How does python handle list unpacking, redefinition, and reference? [duplicate]
I am new to python and am trying to understand how it handles copies vs references in respect to list unpacking. I have a simple code snippet and am looking for an explanation as to why it is behaving ...
2
votes
2
answers
1k
views
Numpy array is modified globally by the function without return [duplicate]
When I use the function that doesn't return anything, the input parameters remain globally unchanged.
For example:
def func(var):
var += 1
a = 0
for i in range(3):
func(a)
print(a)
...
0
votes
1
answer
1k
views
How do python references work? Why do lists share modifications done to other references while integers don't? [duplicate]
The following snippet:
a = [1,2,3,4,5]
b = a
b.append(6)
print(a)
print(b)
prints
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
so when modifying b, we also modify the list accessible through a.
However, ...
3
votes
2
answers
397
views
Python aliasing [duplicate]
I understand that given this code
a = [1,2,3]
b = [4,5,6]
c = a
and then by doing this
a[0] = 0
I wil change first positions of both a and c. Could somebody explain why this doesn't apply when I do ...
0
votes
3
answers
554
views
Why does it show the same value after changing a variable? [duplicate]
I write this code:
a=5
b=4
s=a*b
print(s)
20
then I changed variable "a" to 6:
a=6
print(s)
20
I changed variable "a" and when i say print(a) it shows new variable(6) but when I say print(s) it ...
2
votes
3
answers
278
views
Why variable assignment behaves differently in Python? [duplicate]
I am new to Python and I am quite confused about the following code:
Example 1:
n = 1
m = n
n = 2
print(n) # 2
print(m) # 1
Example 2:
names = ["a", "b", "c"]
...
2
votes
3
answers
458
views
Removing items from dictionaries using del keyword [duplicate]
I am a novice when it comes to using Python language. I want to understand why removing an item from a dictionary using the del keyword is impossible when someone references the item using a variable. ...
user avatar
user13871283
0
votes
3
answers
84
views
Is this an example of call-by-reference, a bug, or something else? [duplicate]
I am writing a little program to create a list of permutations. I read about the algorithm on wikipedia.
My algorithm basically takes an initially sorted list of numbers, and permutes it in place. ...
-2
votes
1
answer
143
views
Output is different than Stdout in Python [duplicate]
I'm new to programming and I'm trying Leetcode. The question asks to store the answer inside nums1. When I print nums1, the stdout shows the correct answer but the output is not the same?
enter image ...
0
votes
1
answer
153
views
python modifies variable that is used as an argument of a function. How to prevent it properly? [duplicate]
If a variable is used as an argument of a function, then all modifications done inside the function with the argument apply to the variable. This is normal and expected, but in many cases undesirable. ...
0
votes
0
answers
85
views
Strange behavior in assigning values to dict variables (Python 3) [duplicate]
Have you ever faced this behavior in assigning values to two (or more) different dict variables using the same list of values?
m1={}
m2={}
token=['a','b','c']
m1['12345']=token
m2['4422']=token
#both ...
-4
votes
2
answers
80
views
Why does the function still minus my dictionary [duplicate]
So, ive been doing my python project for some time, got a big problem about a func
https://pastebin.com/u6ZHXbxc
this function converts goes through each 'e'type in price and checks if its more points ...
0
votes
1
answer
48
views
Mutability in Python and why it happens? [duplicate]
So Im trying get mutability a bit better into my brain and I saw quite a lot of experienced people struggle sometimes.
I made this little test code here:
x = 1
def test():
x = 2
test()
print(x) #...