-
-
Save MostAwesomeDude/ccc2086adb767e1eec8ce543257cb64e to your computer and use it in GitHub Desktop.
Basic demonstration of the lambda/def equivalence in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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