In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how python evaluates multiple conditions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Evaluate multiple conditions
Usually, we need to evaluate multiple conditions. There are several possible options. For numeric values, we can compare the same variable multiple times. In this case, we can link to these comparisons.
# Multiple Comparisons # The typical way if a
< 4 and a >1: # do something here# Do this instead if 1
< a < 4: # do somerthing here 在其他一些情况下,我们可以进行多个相等比较,并且可以使用以下in关键字进行成员测试。 # The typical way if b == "Mon" or b == "Wed" or b == "Fri" or b == "Sun": # do something here# Do this instead, you can also specify a tuple ("Mon", "Wed", "Fri", "Sun") if b in "Mon Wed Fri Sun".split(): # do something here 另一种技术是使用内置的all()和any()函数用于评估多个条件的功能。具体而言,该all()函数将评估何时迭代中的元素全部为True,因此该函数适合于替换一系列AND逻辑比较。另一方面,该any()函数的计算结果为True当迭代中的任何元素为True,因此适合替换一系列OR逻辑运算。相关示例如下所示。 # The typical ways if a < 10 and b >5 and c = = 4: # do somethingif a
< 10 or b >5 or c = 4: # do something# Do these instead if all ([a
< 10, b >5, c = = 4]): # do somethingif any ([a
< 10, b >5, c = = 4]): # do something Thank you for reading! This is the end of the article on "how python evaluates multiple conditions". I hope the above content can be of some help to you, so that 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.