python取商怎么运算_如何从python中的模块`operator`获取数学运算...

以operator.add为例:

>>>import operator as op

>>>op.add(1,2) #means 1 + 2

3

>>>op.add.__name__

'add'

我想要的是:

>>>op.add.math_str

"+"

我可以获得所有那些数学字符串“”,“ – ”,“>”…模块运算符支持运行时?

编辑:

>>> [eval(x) for x in [".".join(("op",x,"__doc__")) for x in dir(op)]]

['abs(a) -- Same as abs(a).',

'add(a, b) -- Same as a + b.',

'and_(a, b) -- Same as a & b.',

'concat(a, b) -- Same as a + b, for a and b sequences.',

'contains(a, b) -- Same as b in a (note reversed operands).',

'delitem(a, b) -- Same as del a[b].',

'delslice(a, b, c) -- Same as del a[b:c].',

'div(a, b) -- Same as a / b when __future__.division is not in effect.',

'str(object) -> string

Return a nice string representation of the object.

If the argument is a string, the return value is the same object.',

上面的代码可以列出大多数运算符字符串,这是否意味着我可以用re模块列出字符串?

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值