python - 为什么我在输出中得到“无”
问题描述
''''为什么我在输出中得到'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))
输出 热 无
''''''
解决方案
问题是print
返回 Nothing 或None
. 因此,当您这样做时,它会将返回的x = print(...)
值分配print
给x
None
然后,当您这样做时return x
,您正在做return None
的就是打印。
推荐阅读
- ubuntu-20.04 - 使用 Cubic 的 Ubuntu Server 20.04 到 Ubuntu Desktop Cinnamon。Cinnamon live 无法正常启动
- chart.js - Chartjs 3.40 和更新版本不能与 Qualtrics 一起使用
- google-chrome-extension - 在 chrome 扩展中使用网络服务发现
- php - 如何让我的 PhP PDF 文件上传更高效?
- docker - Docker - 提交的 MySQL 映像未启动(数据目录不可用)
- c# - 如何使用提交到 git 存储库的 Azure 数据工厂 json 文件通过代码创建组件
- python - 如何在 python 中插入 3D 空间中的值?
- dbt - dbt docs 在 circleci 上生成失败
- django - 尝试编写只读数据库 Django/Apache2/OperationalError
- c - 多个客户端使用 C 和 UDP 停止并等待