def other_new_function():
print "HELLO"
print "Start", other_new_function(), "Stop"
The output of this program is:
Start HELLO
None Stop
Why is NONE
being showed in the output?
Because you're printing "HELLO"
, and not returning it.
Because your function does not return anything, it defaults to returning None
. Hence, the None
that appears.
Change:
def other_new_function():
print "HELLO"
To:
def other_new_function():
return "HELLO"
There's a big difference to returning and printing something from a function:
>>> def func():
... print 1
...
>>> def func2():
... return 1
...
>>> myvar = func()
1 # Printed
>>> myvar2 = func2() # Returned to a variable
>>> print myvar
None
>>> print myvar2
1
Because function 1 prints the value, it never gets returned to a variable.
def other_new_function():
print "HELLO"
NoneType
明示的に値を返さないため、(「なし」として出力されます) を返します。おそらくやりたいことは次のとおりです。
def other_new_function():
return "HELLO"