In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the differences between not and is None in python". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the differences between not and is None in python"?
Reason:
The data obtained by list is empty: display value is []
Different judgments-is None
-not
The two results are not the same: in short:
Not determines the content, while is None involves whether the list or dict declares and defines
Add: interesting phenomena about Python not and is None (the difference between the two)
The author Xiaobai recently encountered an interesting phenomenon in the process of doing exercises.
When using if An is None to implement the judgment condition, the program failed in the end. The A here represents the data of the list type defined earlier. The best way to pass is to change it to if not A.
So what's the difference between judging that An is empty?
When the author finds that An is empty, not An is True, but this does not mean that the object is not defined, nor does it mean that the object has no other properties. It just means that the element in An is empty, that's all.
If you want to see whether an object is defined, use is None to determine.
Add: the difference between X is None and not X in Python's if conditional statement
In algorithm problems and daily work, there are always is None and not appearing in conditional statements, and they are always confused about their uses. I will make a summary here today.
The specific usage of if X is None and if not X
Not in Python is a logical judgment word, combined with Boolean types True and False to use, not True is False,not False is True. After reading some online materials, not X can be understood as
If x is false, then True, else False
Is None in Python is to determine whether an object has a definition.
For example, list1 = [] list2 = Noneprint ("--Test 1muri -") if list1 is None: print ("use of is None, output list1 content:") print (list1) print ("- split line -") if not list1: print ("use of not, output list1 content:") print (list1) print ("--Test 2muri -") if list2 is None: print ("use of is None Output the contents of list2: ") print (list2) print ("-split line-") if not list2: print (" use of not, output list2 content: ") print (list2) can see:
List1 is [], at this time only not judgment has output, because list1 is empty, but it is defined, so None judgment is not valid at this time, so there is no output, while list1 is empty, not empty is true, so output this list1
List2 is None, so both conditions have output. Because None = = None, there is output, and not None is True, so there will also be output.
Thank you for your reading, the above is "what are the differences between not and is None in python". After the study of this article, I believe you have a deeper understanding of the difference between not and is None in python, 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.
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.