根本原因:
python定义函数时,一般都会有指定返回值,如果没有显式指定返回值,那么python就会默认返回值为None
我们输入的代码如下:
def test():
print('aaa')
print(test())
相当于执行了:
def test():
print('aaa')
return None
print(test())
如果不想要有None,那么就要添加返回值
def test():
return 'ccc'
print(test())
本文深入探讨了Python中函数的默认返回值机制,当函数未明确指定返回值时,默认返回None。通过示例代码解释如何避免None的返回,并展示了如何正确地为函数设置返回值。
1637

被折叠的 条评论
为什么被折叠?



