Lambda expressions of python2 are very useful, but they are magical in the form of python2. They cannot print, raise, or assign values ). The following improvements are made to the lambda expression peripheral products based on python2.73 @ ubuntu default, selling a good price :).
In python2, exec can be used, but it is ugly, so it defines several functions, use it.
[Python] #! ...
Def raise _ (ex ):
Raise ex
Def print _ (* l ):
For I in l:
Print I,
Def defval (var, val ):
Globals () [var] = val
Return val
(Lambda: defval ('A', 3) and a = 3 and type (a) or 2 )()
(Lambda: defval ('A', 2) and a = 3 and type (a) or 2 )()
(Lambda x: print _ (x) ('World ')
(Lambda: raise _ (Exception ('Hi ')))()
#! ...
Def raise _ (ex ):
Raise ex
Def print _ (* l ):
For I in l:
Print I,
Def defval (var, val ):
Globals () [var] = val
Return val
(Lambda: defval ('A', 3) and a = 3 and type (a) or 2 )()
(Lambda: defval ('A', 2) and a = 3 and type (a) or 2 )()
(Lambda x: print _ (x) ('World ')
(Lambda: raise _ (Exception ('Hi ')))()
In general, I do not advocate "awesome"... but sometimes it is really much more convenient, and lambda is a super-God in an instant. Gao fushuai =. =.