Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize logical inversion in python

Shulou Source: shulou.com Published: 2022-06-03 15:34:08 10月04日 Update

This article is about how Python implements logical inversion. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

description

1, True and False are logically negated to use not. Not is the logical negation, and ~ is the bitwise negation.

2. True and False correspond to values 1 and 0,~True corresponds to the bitwise inversion of 1, and the result is-2, and the result of not True is False.

examples

print(True)print(~True)print(not True)

The result was:

True-2False

Similarly,~False results in 1, not False results in True

print(False)print(~False)print(not False)

The result was:

False-1True Thank you for reading! About "python how to achieve logic inversion" this article is shared here, I hope the above content can have some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Results logic content more articles good practical examples articles see knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn MySQL Huawei NVidia