我有这个密码:
def the_flying_circus():
if True and True and True and not False:
print "Kevin stinkt"
elif 10 < 4:
print "Justin stinkt"
else:
print "herb-wuerzig"
当我print the_flying_circus
打印Kevin stinkt
时,None
作为回报。我需要False
作为在线教程的回报。为什么我要得到None
,我怎样才能得到True
?你知道吗
Tags:
None
是函数的返回值。没有显式return
语句的函数将返回None
。你知道吗针对您的其他问题:
如果希望函数返回true,请将
最后。如果你想让它返回false,把
最后。你知道吗
如果函数不返回任何其他内容,则返回
None
,因此首先在函数内部打印,然后打印返回的None
。你知道吗如果您用
return
交换print
语句,或者只调用the_flying_circus()
而不是print the_flying_circus()
,您将得到预期的结果。你知道吗然后可以运行函数并打印返回值:
或者你可以:
只需调用函数而不打印返回值:
所需代码如下:
# Make sure that the_flying_circus() returns True def the_flying_circus(antwort): if antwort > 5:
print "H" elif antwort < 5: print "A" else: print "I" return True
无论我输入什么,
the_flying_circus
总是返回True
相关问题 更多 >
编程相关推荐