Skip to content

Commit 459aa53

Browse files
committed
Python Closures
1 parent d4520d7 commit 459aa53

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Programs/P44_Closures.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Author: OMKAR PATHAK
2+
3+
# Wikipedia:
4+
# A closure is a record storing a function[a] together with an environment:
5+
# a mapping associating each free variable of the function (variables that are used locally, but
6+
# defined in an enclosing scope) with the value or reference to which the name was bound when
7+
# the closure was created.A closure—unlike a plain function—allows the function to access those
8+
# captured variables through the closure's copies of their values or references, even when the function
9+
# is invoked outside their scope.
10+
11+
def outerFunction(text):
12+
text = text
13+
14+
def innerFunction():
15+
print(text)
16+
17+
return innerFunction
18+
19+
if __name__ == '__main__':
20+
myFunction = outerFunction('Hey!')
21+
myFunction()]

0 commit comments

Comments
 (0)