Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Priority of Python logical operations

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the priority of Python logic operation". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the priority of Python logic operation".

1. And 'and'

If the left side of the and is False, the left result (False) is returned directly; if the left side of the and is True, the returned result depends on the value on the right. You need true on both sides to return true;. The right side is false, so false is returned as a whole.

2. Or'or'

If the left side of the or is True, the left result (True) is returned directly; if the left side of the or is False, the returned result depends on the value on the right. As long as one side is true, true; will be returned. Although the right side is false, the overall true will be returned.

3. Not 'not'

Not is easy to understand, which is a reverse operation. You need true on both sides to return the current reverse of true;. Currently, false is returned for true, and true is currently returned for false.

For example: not True---- > False;not False--- > True

4. Examples:

# and or not

# priority, () > 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 42) # 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-zero conversion to bool True 0 conversion 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 xdistinct'"

# print (1 or 2) # 1

# print (3 or 2) # 3

# print (0 or 2) # 2

# print (0 or 100) # 100

# print (2 or 100 or 3 or 4) # 2

# print (0 or 4 and 3 or 2)

'x and y x True, then return yawness.'

# print (1 and 2)

# print (0 and 2)

Print (2 or 1

< 3) print(3 >

1 or 2 and 2)

5. Priority of logical operation

The priority of the operator is not > and > or. This priority knowledge point will be applied to the composite operation in the same way as addition, subtraction, multiplication and division. And has a high priority in or and and. If the priority of or is greater than and, the priority of not in false,not and and should be high; if the priority of and is higher than not, true should be returned.

Thank you for reading, the above is the content of "the priority of Python logic operation". After the study of this article, I believe you have a deeper understanding of the priority of Python logic operation, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report