我想构建一个可以执行以下操作的逻辑变量类
x = LogicVar()
y = LogicVar()
property = x -> y
Run Code Online (Sandbox Code Playgroud)
那么这将给...
property(true, true) = true
property(true, false) = false
property(false, true) = true
property(false, false) = true
Run Code Online (Sandbox Code Playgroud)
因为我理想情况下能够做类似的事情
class LogicVar():
...
def __dash_arrow_(self, other):
def ifthen(x, y):
return (not(x) or y)
return ifthen
Run Code Online (Sandbox Code Playgroud)
我知道我可以重载像 + 或 >= 这样的东西,但我不知道我是否可以这样做 -> 即使我看到它在类型提示中使用。
No.->在 Python 中根本不是运算符。Python 语法中唯一->允许使用标记的位置是函数定义中的返回类型注释之前。Python 运算符重载不允许您更改语言语法或创建新运算符。
| 归档时间: |
|
| 查看次数: |
52 次 |
| 最近记录: |