简体   繁体   中英

why does ~(True ^ False) return -2

I tried the following command line in python

In[1]: ~(True ^ False)

and it returned:

Out[1]: -2

Could someone explain this to me please?

Thanks in advance

It's because of how python handles booleans:

True is represented as 1, (See True==1 )

False is represented as 0. (See False==0 )

Without syntactic sugar and abstractions:

x=~(1 ^ 0)
x=~1
x=-2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM