MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/PythonLearning/comments/1m8v0k7/name_rebinding/n544c7d/?context=3
r/PythonLearning • u/Sea-Ad7805 • Jul 25 '25
See Solution made using memory_graph.
38 comments sorted by
View all comments
9
C
7 u/Constant-Past-6149 Jul 25 '25 Just for everyone's understanding lets do mental debugging:a = [1]b = a = [1] (check both id(b) and id(a), the memory location will be same)b = a = [1,2]b = a = [1,2,3]b = [4] (new memory allocation of b, instead of using a's location, check again both id(b) and id(a) and you'll understand).b = [4,5] 5 u/professor_coldheart Jul 25 '25 I was sniped by print(a) instead of print(b). 0 u/[deleted] Jul 27 '25 [deleted] 1 u/TedditBlatherflag Jul 28 '25 No it’s a terrible exam question. Make the variables legible and clear. If “a” was “foo” and “b” was “bar” then the question is about binding. If it’s “did you notice it said a” it’s just a trick question.
7
Just for everyone's understanding lets do mental debugging:
a = [1]
b = a = [1] (check both id(b) and id(a), the memory location will be same)
b = a = [1,2]
b = a = [1,2,3]
b = [4] (new memory allocation of b, instead of using a's location, check again both id(b) and id(a) and you'll understand).
b = [4,5]
5 u/professor_coldheart Jul 25 '25 I was sniped by print(a) instead of print(b). 0 u/[deleted] Jul 27 '25 [deleted] 1 u/TedditBlatherflag Jul 28 '25 No it’s a terrible exam question. Make the variables legible and clear. If “a” was “foo” and “b” was “bar” then the question is about binding. If it’s “did you notice it said a” it’s just a trick question.
5
I was sniped by print(a) instead of print(b).
0 u/[deleted] Jul 27 '25 [deleted] 1 u/TedditBlatherflag Jul 28 '25 No it’s a terrible exam question. Make the variables legible and clear. If “a” was “foo” and “b” was “bar” then the question is about binding. If it’s “did you notice it said a” it’s just a trick question.
0
[deleted]
1 u/TedditBlatherflag Jul 28 '25 No it’s a terrible exam question. Make the variables legible and clear. If “a” was “foo” and “b” was “bar” then the question is about binding. If it’s “did you notice it said a” it’s just a trick question.
1
No it’s a terrible exam question. Make the variables legible and clear. If “a” was “foo” and “b” was “bar” then the question is about binding. If it’s “did you notice it said a” it’s just a trick question.
9
u/Constant-Past-6149 Jul 25 '25
C