From 2b11ea92981ca3dad4a6fde70d778303d60ef0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 1 Feb 2019 11:05:33 +0100 Subject: [PATCH] Closure --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 2d7137e..b6e88cc 100644 --- a/README.md +++ b/README.md @@ -536,6 +536,10 @@ creature = Creature() Closure ------- +**We have a closure in Python when:** +* **A nested function references a value of its enclosing function, and then** +* **the enclosing function returns the nested function. + ```python def get_multiplier(a): def out(b): @@ -549,6 +553,8 @@ def get_multiplier(a): 30 ``` +* **If multiple nested functions within enclosing function reference the same value, that value gets shared.** + #### Or: ```python from functools import partial