deffun(a = []):
a += [1]
return a
fun()
print(fun()) # [1, 1]
issues I had with the tool you linked
I tried to make a link to this code in this visual debugger, but a link is made broken and can’t be used without urlencoding spaces (I guess). Also the tool doesn’t produce visual output in DuckDuckGo browser on Android
The following URL has been copied to your clipboard with:
The current code
Set breakpoints
Playback timestep
Play/Pause state
https://memory-graph.com/#code=+%23+What+is+the+output+of+this+Python+program? +++ def+fun(a+=+[]):+ ++++a++=+[1] ++++return+a fun()+print(fun())
The latter doesn’t work, and I didn’t think of checking the former
There’s also a gotcha with default parameters:
def fun(a = []): a += [1] return a fun() print(fun()) # [1, 1]
issues I had with the tool you linked
I tried to make a link to this code in this visual debugger, but a link is made broken and can’t be used without urlencoding spaces (I guess). Also the tool doesn’t produce visual output in DuckDuckGo browser on Android
You can just write your code and then press “Get URL” to get the link: https://memory-graph.com/#code=def+fun(a+%3D+[])%3A ++++a+%2B%3D+[1] ++++return+a fun() print(fun())+%23+[1%2C+1]
DuckDuckGo problem, thanks for reporting.
Yeah, I wrote code and pressed get URL, but then I copied what was shown in the window
The clipboard content:
https://memory-graph.com/#code=+%23+What+is%2Bthe+output+of+this+Python+program%3F%0A+++%0Adef+fun%28a+%3D+%5B%5D%29%3A+%0A++++a+%2B%3D+%5B1%5D%0A++++return+a%0Afun%28%29+print%28fun%28%29%29
The window text:
The following URL has been copied to your clipboard with: The current code Set breakpoints Playback timestep Play/Pause state https://memory-graph.com/#code=+%23+What+is+the+output+of+this+Python+program? +++ def+fun(a+=+[]):+ ++++a++=+[1] ++++return+a fun()+print(fun())
The latter doesn’t work, and I didn’t think of checking the former
Thanks for reporting, should be fixed now.