how to use _ in a function
laocan opened this issue · 4 comments
I've try :
print math.sin(_)
it turn out to be wrong, but it works for:
lambda x: math.sin(x)
Does _ always be same as lambda caluse?
any limitation?
thx ~~
@laocan There is no way in Python to work with expressions like math.sin(_)
cause of evaluation order. And, btw, there is no necessity for doing this in you example. math.sin(_)
most probably means lambda x: math.sin(x)
which is equivalent to math.sin
.
I would also like to suggest having a look at the tests. It does cover most of operator
s (e.g. operator.add
). It also handles method calls as well as some neat stuff like slices!
BTW, If you need to express math.ldexp(10, _)
use partial(math.ldexp, 10)
. If you need math.ldexp(_, 10)
use partial(flip(math.ldexp), 10)
.
Is there something else that I can help you with?
I got it.
thx~