changeset 817:9f42400dcd83

attempt to illustrate anoymous functions
author Jeff Hammel <k0scist@gmail.com>
date Tue, 29 Nov 2016 16:33:39 -0800
parents c0638ac7fb56
children 352530cbf195
files python/example/anonomouse.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/example/anonomouse.py	Tue Nov 29 16:33:39 2016 -0800
@@ -0,0 +1,19 @@
+
+def foo(a):
+
+    c = ['hi']
+
+    def bar(n):
+        d = c[:][0].upper()
+        return '{} {}!'.format(d, a) * n
+
+    fleem = lambda n: '{} {}!'.format(c[:][0].upper(), a) * n
+
+    c = ['hello']
+
+    return (bar,
+            fleem)
+
+_bar, _fleem = foo("world")
+print (_bar(2))
+print (_fleem(2))