Linked Questions

7 votes
4 answers
1k views

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 = ...
user1266138's user avatar
4 votes
4 answers
1k views

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

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

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

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

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

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 ...
hgs's user avatar
  • 141
2 votes
3 answers
278 views

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"] ...
Yang Yang's user avatar
  • 922
2 votes
3 answers
458 views

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
0 votes
3 answers
84 views

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

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 ...
volrriti's user avatar
0 votes
1 answer
153 views

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

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

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 ...
Noway's user avatar
  • 11
0 votes
1 answer
48 views

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) #...

15 30 50 per page
1
2 3 4 5