| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
a = lambda: 3 |
| 5 |
|
| 6 |
a() |
| 7 |
|
| 8 |
x = [] |
| 9 |
a = lambda x: x |
| 10 |
|
| 11 |
a(0) |
| 12 |
|
| 13 |
|
| 14 |
(lambda x: x)(3.0) |
| 15 |
|
| 16 |
arg_l = lambda x, y: y, x |
| 17 |
|
| 18 |
arg_l[0]('', 1.0) |
| 19 |
|
| 20 |
arg_l[1] |
| 21 |
|
| 22 |
arg_l = lambda x, y: (y, x) |
| 23 |
args = 1,"" |
| 24 |
result = arg_l(*args) |
| 25 |
|
| 26 |
result |
| 27 |
|
| 28 |
result[0] |
| 29 |
|
| 30 |
result[1] |
| 31 |
|
| 32 |
def with_lambda(callable_lambda, *args, **kwargs): |
| 33 |
return callable_lambda(1, *args, **kwargs) |
| 34 |
|
| 35 |
|
| 36 |
with_lambda(arg_l, 1.0)[1] |
| 37 |
|
| 38 |
with_lambda(arg_l, 1.0)[0] |
| 39 |
|
| 40 |
with_lambda(arg_l, y=1.0)[0] |
| 41 |
|
| 42 |
with_lambda(lambda x: x) |
| 43 |
|
| 44 |
with_lambda(lambda x, y: y, y=1.0) |
| 45 |
|
| 46 |
arg_func = lambda *args, **kwargs: (args[0], kwargs['a']) |
| 47 |
|
| 48 |
arg_func(1, 2, a='', b=10)[0] |
| 49 |
|
| 50 |
arg_func(1, 2, a=[], b=10)[1] |
| 51 |
|
| 52 |
|
| 53 |
a = lambda: 3 |
| 54 |
|
| 55 |
a.__closure__ |
| 56 |
|
| 57 |
class C(): |
| 58 |
def __init__(self, foo=1.0): |
| 59 |
self.a = lambda: 1 |
| 60 |
self.foo = foo |
| 61 |
|
| 62 |
def ret(self): |
| 63 |
return lambda: self.foo |
| 64 |
|
| 65 |
def with_param(self): |
| 66 |
return lambda x: x + self.a() |
| 67 |
|
| 68 |
lambd = lambda self: self.foo |
| 69 |
|
| 70 |
|
| 71 |
C().a() |
| 72 |
|
| 73 |
|
| 74 |
C('foo').ret()() |
| 75 |
|
| 76 |
index = C().with_param()(1) |
| 77 |
|
| 78 |
['', 1, 1.0][index] |
| 79 |
|
| 80 |
|
| 81 |
C().lambd() |
| 82 |
|
| 83 |
C(1).lambd() |
| 84 |
|
| 85 |
|
| 86 |
def xy(param): |
| 87 |
def ret(a, b): |
| 88 |
return a + b |
| 89 |
|
| 90 |
return lambda b: ret(param, b) |
| 91 |
|
| 92 |
|
| 93 |
xy(1)(2) |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
class Test(object): |
| 99 |
def __init__(self, pred=lambda a, b: a): |
| 100 |
self.a = 1 |
| 101 |
|
| 102 |
self.a |
| 103 |
|
| 104 |
pred(1.0, 2) |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
[a for a in [1,2] if (lambda: 3)][0] |