天天看点

not vs ~

import pandas as pd
df = pd.DataFrame()
print(df.empty)	
# True
print(not df.empty) 
# False
print(~df.empty)
# -2
           

~

:按位取反。所以 ~True 相当于 0000 0001转换成 1111 1110,即-2;

not 是与或非的非,~True为False。