gpt4 book ai didi

python - 我可以在 python 中重载 -> 吗?

转载 作者:行者123 更新时间:2023-12-02 18:07:23 26 4
gpt4 key购买 nike

我想构建一个可以执行以下操作的逻辑变量类

x = LogicVar()
y = LogicVar()

property = x -> y

然后这将给出...

property(true, true) = true
property(true, false) = false
property(false, true) = true
property(false, false) = true

因为理想情况下我能够做类似的事情

class LogicVar():
...

def __dash_arrow_(self, other):
def ifthen(x, y):
return (not(x) or y)
return ifthen

我知道我可以重载像 + 或 >= 这样的东西,但我不知道我是否可以这样做 -> 即使我看到它在类型提示中使用。

最佳答案

没有。 -> 在 Python 中根本不是运算符。 Python 语法中唯一允许使用 -> 标记的位置是函数定义中返回类型注释之前。 Python 运算符重载不允许您更改语言语法或创建新运算符。

关于python - 我可以在 python 中重载 -> 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72976208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com