Created
August 25, 2018 04:21
-
-
Save Fhernd/999932df7a1d3dba6c0d6b9fcd9f79ce to your computer and use it in GitHub Desktop.
Captura de variables en una función anónima. OrtizOL.
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
x = 5 | |
# Uso de la variable libre `x`: | |
sumar1 = lambda a: a + x | |
x = 7 | |
sumar2 = lambda a: a + x | |
print(sumar1(20)) | |
print(sumar2(20)) | |
# Captura de la variable libre `x` como un valor por defecto: | |
x = 5 | |
sumar1 = lambda a, x = x: a + x | |
x = 7 | |
sumar2 = lambda a, x = x: a + x | |
print(sumar1(20)) | |
print(sumar2(20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment