class Node:
def __init__(self,a,b):
self._a=a
self._b=b
def __lt__(self,other):
return self._a<other._a
a=Node(1,2)
b=Node(0,4)
print(a>b)
Run Code Online (Sandbox Code Playgroud)
上面的代码显示 True。
class Node:
def __init__(self,a,b):
self._a=a
self._b=b
def __lt__(self,other):
return self._a<other._a
def __eq__(self,other):
return self._a==other._a
a=Node(1,2)
b=Node(0,4)
print(a>=b)
Run Code Online (Sandbox Code Playgroud)
上面的代码显示了 TypeError: 'Node' 和 'Node.js 实例之间不支持'<='。
为什么仅定义lt就可以进行 >(即gt)操作?为什么同时定义lt和eq会使 <= 不可能?
#include<iostream>
using namespace std;
#define C 1<<(8*1)
int main(){
if(C==256){
int a=C;
cout<<a;
}
}
Run Code Online (Sandbox Code Playgroud)
我的期望是 256,但它打印出 18。这有什么问题吗?谢谢!