【问题标题】:How to return an operator from a function? [duplicate]如何从函数中返回运算符? [复制]
【发布时间】:2020-10-17 13:12:12
【问题描述】:

如何在 python 中返回运算符?我试过了,但它显然不起作用:

def plus():
    return +

不使用加号也可以写出这样的代码吗?

print(3plus()4)

【问题讨论】:

标签: python operator-keyword


【解决方案1】:

像这样

import operator
print(operator.add(3,4))

【讨论】:

  • 我希望函数只返回运算符,这可能吗?没有参数
猜你喜欢
  • 2020-06-03
  • 2014-06-05
  • 1970-01-01
  • 2023-03-03
  • 2020-03-24
  • 2013-06-09
  • 2020-12-03
  • 2016-01-14
相关资源
最近更新 更多