正在加载图片...
None Indicates that Nothing is Returned The special value None represents nothing in Python A function that does not explicitly return a value will return None Careful:None is not displayed by the interpreter as the value of an expression >>def does_not_return_square(x): XX ------- No return >>does_not_return_square(4)+----- None value is not displayed The name sixteen >>isixteen =does_not_return_square(4) is now bound to >>sixteen +4 the value None Traceback (most recent call last): File "<stdin>",line 1,in <module> TypeError:unsupported operand type(s)for +'NoneType'and 'int'>>> does_not_return_square(4) >>> sixteen + 4 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' >>> sixteen = does_not_return_square(4) None Indicates that Nothing is Returned ● The special value None represents nothing in Python ● A function that does not explicitly return a value will return None ● Careful: None is not displayed by the interpreter as the value of an expression >>> def does_not_return_square(x): ... x * x ... No return None value is not displayed The name sixteen is now bound to the value None
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有