How do you often see these situations when you're making a judgment on python?
If True:
If s:
If key is not None:
If not s:
And so on that judgment
Understand
1 NULL is a data type of without as
S= "
L=[]
D = {}
t = ()
All of these represent no elements
In [Sat]: s= ' in []: ' If s: ....: print ' s string not empty ' ....: ' Else: ....: print ' s string is empty ' ....: s string is empty
Often, judging whether a string has a ' out of space ' or ' \ n ' element is commonly judged as follows
If S.strip (): Passelse:pass
2 None Type
None is a nonetype type, note is type
in [[]: A = Nonein []: Type (a) out[49]: Nonetypein [[]: Type (None) out[50]: Nonetype
in [+]: If A is not none: ....: print ' A not none ' ...: Else: ...: print ' None ' ....: none
Commonly used to determine whether an element is of type none
If A is not None:passelse:pass
None often appears in the default parameter assignment of the function Def f (s=none) and return value in the None
3 Boolean type True False
In [the]: if True: ....: print ' true ' ....: ' Else ' ...: print ' false ' ....: true
Common: return True of a function or if judgment
If True equals if not False
in [+]: not falseout[47]: True
4 Not for negate
Note that the counter can not be used!
If not s:
This article is from the "Tridewah operation and maintenance work Road" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1767091
The understanding and application of NULL without none True in Python