Mercurial > hg > config
comparison python/example/anonomouse.py @ 817:9f42400dcd83
attempt to illustrate anoymous functions
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 29 Nov 2016 16:33:39 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
816:c0638ac7fb56 | 817:9f42400dcd83 |
---|---|
1 | |
2 def foo(a): | |
3 | |
4 c = ['hi'] | |
5 | |
6 def bar(n): | |
7 d = c[:][0].upper() | |
8 return '{} {}!'.format(d, a) * n | |
9 | |
10 fleem = lambda n: '{} {}!'.format(c[:][0].upper(), a) * n | |
11 | |
12 c = ['hello'] | |
13 | |
14 return (bar, | |
15 fleem) | |
16 | |
17 _bar, _fleem = foo("world") | |
18 print (_bar(2)) | |
19 print (_fleem(2)) |