Python—None

None is a special constant.
None is not False.
None other than 0.
None not an empty string.
None has its own data type NoneType, and is NoneTypethe only value.
None but the object of a null value, you can assign None to any variable, but you can not create other NoneTypeobjects.


Python in what form data is empty it?
 
None Constants
Constant False
empty list
empty tuple
-empty
empty dictionary
integer of 0
float 0.0
empty string ''


None default function generally used for a parameter indicating the

def func(a, b=None):
    if b is None:
        print('b is None')
    if a is not None:
        print('a :', a)
        a = None
        print('a :', a)
        print('a is not None :', a is not None)
        print('not None :', not None)
    return None

if not func(666):
    print('not func(666) -> True')

 
Output:

b is None
a : 666
a : None
a is not None : False
not None : True
not func(666) -> True

 


Finally, look to deepen the impression

bool(None) # False
not None is bool(not None) # True
# How to use ↓
object is None # None和任何其他数据类型对象比较永远返回False
object is not None

Guess you like

Origin www.cnblogs.com/malinqing/p/11285437.html