Skip to content

Instantly share code, notes, and snippets.

@MostAwesomeDude
Created August 24, 2021 16:35
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 MostAwesomeDude/ccc2086adb767e1eec8ce543257cb64e to your computer and use it in GitHub Desktop.
Save MostAwesomeDude/ccc2086adb767e1eec8ce543257cb64e to your computer and use it in GitHub Desktop.
Basic demonstration of the lambda/def equivalence in Python
[simpson@harley ~/nixpkgs] 2 ( ^^) $ nix-shell -p python3
[nix-shell:~/nixpkgs]$ python
Python 3.8.8 (default, Feb 19 2021, 11:04:50)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dis import dis
>>> def f(x): return x + x
...
>>> g = lambda x: x + x
>>>
>>> dis(f)
1 0 LOAD_FAST 0 (x)
2 LOAD_FAST 0 (x)
4 BINARY_ADD
6 RETURN_VALUE
>>> dis(g)
1 0 LOAD_FAST 0 (x)
2 LOAD_FAST 0 (x)
4 BINARY_ADD
6 RETURN_VALUE
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment