None还可以是函数定义可选参数的一个默认值,设置成默认值时实参在调用该函数时可以不输入与None绑定的元素

 1 >>> def add_and_maybe_multiply(a,b,c=None):
 2     result = a+b
 3     if c is not None:
 4         result = result*c
 5     return result
 6 
 7 >>> add_and_maybe_multiply(2,3,' ')#实参为空格,返回空格
 8 '     '
 9 >>> add_and_maybe_multiply(2,3,'')#实参为空,返回为空
10 ''
11 >>> add_and_maybe_multiply(2,3,4)
12 20
13 >>> add_and_maybe_multiply(2,3)#实参缺失,返回line2的结果
14 5
原文地址:https://www.cnblogs.com/dmdoge/p/5596354.html