annotate python/example/anonomouse.py @ 854:66321798ac82

[git] update for modern times
author Jeff Hammel <k0scist@gmail.com>
date Mon, 11 Dec 2017 16:56:22 +0000
parents 9f42400dcd83
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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))