Skip to content

Commit 437b2ef

Browse files
committed
Demonstration of lambda function and global variables
1 parent 6ccbc07 commit 437b2ef

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env python
2+
#
3+
#
4+
# This program demonstrates how lambda functions interact with surrounding scopes
5+
6+
glob = 8
7+
8+
f = lambda x: x-glob
9+
10+
print f(2)
11+
12+
glob = 15
13+
14+
print f(3)
15+
16+
def incr(n): return lambda x: x-n
17+
h = incr(2)
18+
i = incr(4)
19+
print h(3), i(3)
20+
print incr(6)(9)
21+

0 commit comments

Comments
 (0)