Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created August 25, 2018 04:21
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 Fhernd/999932df7a1d3dba6c0d6b9fcd9f79ce to your computer and use it in GitHub Desktop.
Save Fhernd/999932df7a1d3dba6c0d6b9fcd9f79ce to your computer and use it in GitHub Desktop.
Captura de variables en una función anónima. OrtizOL.
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