Skip to content

Instantly share code, notes, and snippets.

@klange
Created July 24, 2022 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klange/7f94fdc158df2a1f2d556ed045669338 to your computer and use it in GitHub Desktop.
Save klange/7f94fdc158df2a1f2d556ed045669338 to your computer and use it in GitHub Desktop.
>>> def foo(a=[]):
> a.append(1)
> print(a)
>
<foo(a=...) from <stdin>>
1 0 GET_LOCAL 0 (a, kwarg)) +a
2 TEST_ARG 4 (to 9)
5 MAKE_LIST 0
7 SET_LOCAL_POP 0 (a, kwarg))
2 >> 9 GET_LOCAL 0 (a, kwarg))
11 GET_METHOD 0 'append'
13 CONSTANT 1 1
15 CALL_METHOD 1
17 POP
3 18 GET_GLOBAL 2 'print'
20 GET_LOCAL 0 (a, kwarg))
22 CALL 1
24 POP
25 NONE -a
26 RETURN
<<module>() from <stdin>>
3 0 CLOSURE 1 <function foo>
2 DEFINE_GLOBAL 0 'foo'
4 4 NONE
5 RETURN
>>> foo()
<<module>() from <stdin>>
1 0 GET_GLOBAL 0 'foo'
2 CALL 0
4 RETURN
[1]
>>> foo()
<<module>() from <stdin>>
1 0 GET_GLOBAL 0 'foo'
2 CALL 0
4 RETURN
[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment