In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the three major application schemes of Python logic operation, the content is very detailed, interested friends can refer to, hope to be helpful to you.
There are many problems to be solved in the operation of Python logic. In actual use, there are three kinds: and, or, not. Correspond to and, OR, and no, respectively.
For example:
# coding:utf-8 test1 = 12 test2 = 0 print (test1 > test2) and (test1 > 14) # result = False print (test1
< test2) or (test1 >-1) # result = True print (not test1) # result = False print (not test2) # result = True
Strictly speaking, the Operand of a logical operator should be a Boolean expression. However, the Python logic operation is more flexible in dealing with this. Even if the operands are numbers, the interpreter treats them as "expressions". The Boolean value of a non-zero number is 1, and the Boolean value of 0 is 0.
For example:
# coding:utf-8 test1 = 12 test2 = 0 print (test1 and test2) # result = 0 print (test1 or test2) # result = 12 print (not test1) # result = Flase print (not test2) # reslut = True
In Python logical operations, the empty string is false and the non-empty string is true. A number that is not zero is true.
The logical operation rules between numbers and strings and between strings are as follows:
For the and operator: as long as the expression on the left is true, the value returned by the entire expression is the value of the expression on the right, otherwise, the value of the expression on the left is returned for the or operator: as long as the expressions on both sides are true, the result of the entire expression is the value of the expression on the left.
If it is true and false, the value of the truth expression is returned, and if both are false, such as null and 0, the value on the right is returned. (null or 0) for example:
# coding:utf-8
Test1 = 12
Test2 = 0
Test3 =''
Test4 = "First"
Print test1 and test3 # result =''
Print test3 and test1 # result =''
Print test1 and test4 # result = "First"
Print test4 and test1 # result = 12
Print test1 or test2 # result = 12
Print test1 or test3 # result = 1212 print test3 or test4
# result = "First"
Print test2 or test4 # result = "First"
Print test1 or test4 # result = 12
Print test4 or test1 # result = "First"
Print test2 or test3 # result =''
Print test3 or test2 # result = 0
On the Python logic operation of the three major applications shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.