Comparative Analysis of the methods of judging variables by python
This article mainly explains "the comparative analysis of the methods of judging variables by python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the "comparative analysis of the methods of judging variables in python".
1. If x is not None is the best way to write, clear and error-free.
2, the premise of using if not x is: it must be clear that x equals None, False, empty string "", empty list [], empty dictionary {}, empty tuple () does not affect your judgment.
Three methods
The first is if x is None.
The second is if not x:
The third is if not x is None.
# Python > > x = [] > > y = None > x is NoneFalse > > y is NoneTrue > not xTrue > > not yTrue > not x is None > > True > not y is NoneFalse > at this point, I believe you have a deeper understanding of "comparative analysis of methods for judging variables by python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!