forked from OmkarPathak/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP44_Closures.py
More file actions
21 lines (16 loc) · 740 Bytes
/
P44_Closures.py
File metadata and controls
21 lines (16 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Author: OMKAR PATHAK
# Wikipedia:
# A closure is a record storing a function[a] together with an environment:
# a mapping associating each free variable of the function (variables that are used locally, but
# defined in an enclosing scope) with the value or reference to which the name was bound when
# the closure was created.A closure—unlike a plain function—allows the function to access those
# captured variables through the closure's copies of their values or references, even when the function
# is invoked outside their scope.
def outerFunction(text):
text = text
def innerFunction():
print(text)
return innerFunction
if __name__ == '__main__':
myFunction = outerFunction('Hey!')
myFunction()