Issue
I want to build a logic variable class that can do the following
x = LogicVar()
y = LogicVar()
property = x -> y
then this will give...
property(true, true) = true
property(true, false) = false
property(false, true) = true
property(false, false) = true
because I would be ideally be able to do something like
class LogicVar():
...
def __dash_arrow_(self, other):
def ifthen(x, y):
return (not(x) or y)
return ifthen
I know I can overload stuff like + or >=, but I don't know whether I can do -> even though I see it used in type hints.
Solution
No. ->
is not an operator at all in Python. The only place a ->
token is permitted in the Python grammar is before the return type annotation in a function definition. Python operator overloading does not allow you to change the language syntax or create new operators.
Answered By - user2357112
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.