我试图调用一些在testlib.py中定义的方法,不明白为什么输出中有额外的“无”?谢谢。
在代码中调用testlib.py
print testlib.globalFoo()
f = testlib.Foo()
print f.getValue()testlib.py
class Foo:
def __init__(self):
pass
def getValue(self):
print 'get value in class Foo'
def globalFoo():
print 'in global foo'输出
in global foo
None <= confusion here
get value in class Foo
None <= confusion here发布于 2016-09-16 17:41:01
在globalFoo()函数中:它不仅打印出"in globalFoo“,该函数还返回一个'None‘
This returned value of None is supplied to your print statement:
print testlib.globalFoo() is actually:
print 'None'
when you call testlib.globalFoo(), within the function, it correctly prints 'in global foo'.另一个none类似于返回的getValue()值,后者返回'None‘。
https://stackoverflow.com/questions/39537134
复制相似问题