Python logical operators

Source: Internet
Author: User
Tags logical operators wrapper

True = T

False = F

Not Not X Boolean "Non"-returns False if X is True. If X is False, it returns TRUE. Not (A and B) returns False

?

and X and Y Boolean "and"-if x is False,x and y returns FALSE, otherwise it returns the computed value of Y. (A and B) returns.

?

Or X or Y Boolean "or"-if X is non-0, it returns the value of x, otherwise it returns the computed value of Y. (A or B) return

?

(A and B) or (C and (not D))

=false or (True and true)

=false or True

=true

------------------------------------------------------------------------

#and or not
#优先级, () > Not > and > or
# print (2 > 1 and 1 < 4)
# print (2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
# T or T or F
#T or F
# print (3>4 or 4<3 and 1==1) # F
# Print (1 < 2 and 3 < 4 or 1>2) # T
# print (2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
# print (1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
# print (1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
# print (not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F

#ps int----> BOOL non 0 converts to bool True 0 converts to bool is false
# Print (bool (2))
# Print (bool (-2))
# print (bool (0))
# #bool--->int
# print (int (True)) # 1
# print (int (False)) # 0


"' X or y x True, then return x '"
# print (1 or 2) # 1
# print (3 or 2) # 3
# print (0 or 2) # 2
# print (0 or 100) # 100


# Print (2 or 3 or 4) # 2

# print (0 or 4 and 3 or 2)
"' X and y x True, then return y ' '
# Print (1 and 2)
# print (0 and 2)
Print (2 or 1 < 3) #2
Print (3 > 1 or 2 and 2) #True

Python logical operators

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.