首页 > 解决方案 > 为什么我在输出中得到“无”

问题描述

''''为什么我在输出中得到'none'

def foo(temp): if temp > 25: x= print('hot')

elif temp >15 and temp < 25 :
     x= print('warm')
     
   

elif temp <15 :
    x = print('cold')
   
return x
 

打印(富(66))

输出 热 无

''''''

标签: pythonfunction

解决方案


问题是print返回 Nothing 或None. 因此,当您这样做时,它会将返回的x = print(...)值分配printxNone

然后,当您这样做时return x,您正在做return None的就是打印。


推荐阅读