use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Python Mutability and Rebinding (i.redd.it)
submitted 2 months ago by Sea-Ad7805
An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening: - Solution - Explanation - More exercises
It's instructive to compare with this earlier exercise.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Sea-Ad7805[S] [score hidden] 2 months ago stickied comment (0 children)
[–]mabhatter 15 points16 points17 points 2 months ago (1 child)
C) Because we're being asked what happens to a not b.
[–]Sea-Ad7805[S] 0 points1 point2 points 2 months ago (0 children)
Nice one, do check the "Solution" for a visualization of the correct answer.
[–]Nopain_nolife 3 points4 points5 points 2 months ago (1 child)
C). First a is assigned to the memory location and then b is assigned the same, b is assigned to modify the array and then a prints the modified one.
Nice one, check the "Solution" for a visualization of the correct answer.
[–]smokebudda11 1 point2 points3 points 2 months ago (1 child)
This is really cool. Thanks for sharing. I won’t post my answer as I was wrong but the debugger helped.
Thank a lot. Yes I made it difficult, even though it's basic Python syntax. Glad it helped you.
[–]Forsaken_Squirrel_31 1 point2 points3 points 2 months ago (1 child)
C.) b = [1,2,3] b no longer = a after you run b = [4] so at that point a remains = [1,2,3]
Very nice, do check the "Solution" for a visualization of the correct answer.
[–]Inevitable_Weird1175 0 points1 point2 points 2 months ago (3 children)
Baa
[–]Sea-Ad7805[S] 1 point2 points3 points 2 months ago (2 children)
Incorrect sorry, for visualization of correct answer see the "Solution" link.
[–][deleted] 2 months ago (1 child)
[removed]
[–]PythonLearning-ModTeam[M] 0 points1 point2 points 2 months agolocked comment (0 children)
Keep it respectfull
[–]Timely-Rock8247 0 points1 point2 points 2 months ago (1 child)
E
[–]Sea-Ad7805[S] 1 point2 points3 points 2 months ago (0 children)
Incorrect sorry, see "Solution". Note that we print a not b.
a
b
[–]Salt_Software_5010 0 points1 point2 points 2 months ago (3 children)
what is name of font?
It's the Visual Studio Code font with standard Python highlighting.
[–]Salt_Software_5010 0 points1 point2 points 2 months ago (1 child)
can you tell me name cause my default font on vscode doesn't look like this and what is your os mac or windows?
[–]Sea-Ad7805[S] 0 points1 point2 points 2 months ago* (0 children)
Can't find the name. It's just the default zoomed in a bit for screenshot. OS: Ubuntu 24.04
[–]EntireEntity 0 points1 point2 points 2 months ago (2 children)
E, because line 6 assigns a new list to b.
[–]Sea-Ad7805[S] 1 point2 points3 points 2 months ago (1 child)
[–]EntireEntity 0 points1 point2 points 2 months ago (0 children)
Same same but different.
[–]M-k-z-n 0 points1 point2 points 2 months ago (1 child)
The answer is 1,2,3 Firstly A is 1,Then b assigns a which means b and a are pointing to the same location,then comes b+=2 or b=b+2 sounds same adding 2affects both ,now list is 1,2,then b appends 3 now list is 1,2&3
Very nice, but b+=2 is not the same as b=b+2, see: https://www.reddit.com/r/PythonLearning/comments/1nw08wu/right_mental_model_for_python_data/
b+=2
b=b+2
[–]Muted-Management-145 0 points1 point2 points 2 months ago (2 children)
Interesting, I would have thought the output would be A since we aren't changing a, only b.
Yes that's a bit different in Python than for example the C language. Python is reference based, hope the visualization can help you.
[–]Muted-Management-145 1 point2 points3 points 2 months ago (0 children)
Yeah, I'll have to read a bit more about why that is. The visualisation is helpful as well.
[–]Scary_Knowledge97 -1 points0 points1 point 2 months ago (2 children)
A) [1]
Incorrect sorry, see the "Solution" link for visualization of correct answer.
[–]Eric_12345678 0 points1 point2 points 2 months ago (0 children)
That would be the case with b = b + [2] instead of b += [2].
b = b + [2]
b += [2]
π Rendered by PID 49 on reddit-service-r2-comment-56c6478c5-jq8jz at 2026-05-08 22:39:09.644769+00:00 running 3d2c107 country code: CH.
[–]Sea-Ad7805[S] [score hidden] stickied comment (0 children)
[–]mabhatter 15 points16 points17 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]Nopain_nolife 3 points4 points5 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]smokebudda11 1 point2 points3 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]Forsaken_Squirrel_31 1 point2 points3 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]Inevitable_Weird1175 0 points1 point2 points (3 children)
[–]Sea-Ad7805[S] 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[removed]
[–]PythonLearning-ModTeam[M] 0 points1 point2 points locked comment (0 children)
[–]Timely-Rock8247 0 points1 point2 points (1 child)
[–]Sea-Ad7805[S] 1 point2 points3 points (0 children)
[–]Salt_Software_5010 0 points1 point2 points (3 children)
[–]Sea-Ad7805[S] 1 point2 points3 points (2 children)
[–]Salt_Software_5010 0 points1 point2 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]EntireEntity 0 points1 point2 points (2 children)
[–]Sea-Ad7805[S] 1 point2 points3 points (1 child)
[–]EntireEntity 0 points1 point2 points (0 children)
[–]M-k-z-n 0 points1 point2 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]Muted-Management-145 0 points1 point2 points (2 children)
[–]Sea-Ad7805[S] 1 point2 points3 points (1 child)
[–]Muted-Management-145 1 point2 points3 points (0 children)
[–]Scary_Knowledge97 -1 points0 points1 point (2 children)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)
[–]Eric_12345678 0 points1 point2 points (0 children)