Mercurial > hg > config
annotate python/example/anonomouse.py @ 832:b9be1237fffa
revert to python2 for time being
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 19 Feb 2017 20:27:07 -0800 |
parents | 9f42400dcd83 |
children |
rev | line source |
---|---|
817
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
1 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
2 def foo(a): |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
3 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
4 c = ['hi'] |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
5 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
6 def bar(n): |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
7 d = c[:][0].upper() |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
8 return '{} {}!'.format(d, a) * n |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
9 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
10 fleem = lambda n: '{} {}!'.format(c[:][0].upper(), a) * n |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
11 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
12 c = ['hello'] |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
13 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
14 return (bar, |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
15 fleem) |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
16 |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
17 _bar, _fleem = foo("world") |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
18 print (_bar(2)) |
9f42400dcd83
attempt to illustrate anoymous functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
19 print (_fleem(2)) |