Python if 语句
2023-02-18 15:29:18 时间
Python if 语句
Python3 实例
以下实例通过使用 if...elif...else 语句判断数字是正数、负数或零:
实例(Python 3.0+)
# Filename : test.py
# author by : www.runoob.com
# 用户输入数字
num = float(input("输入一个数字: "))
if num > 0:
print("正数")
elif num == 0:
print("零")
else:
print("负数")
执行以上代码输出结果为:
输入一个数字: 3 正数
我们也可以使用内嵌 if 语句来实现:
实例(Python 3.0+)
# Filename :test.py
# author by : www.runoob.com
# 内嵌 if 语句
num = float(input("输入一个数字: "))
if num >= 0:
if num == 0:
print("零")
else:
print("正数")
else:
print("负数")
执行以上代码输出结果为:
输入一个数字: 0 零
Python3 实例
相关文章
- pybind11 大大简化 Python 调用 C/C++
- 4 年时间让 Python 性能提升 5 倍
- Python 越来越优雅了
- Python-3.12 性能分析特性
- 手把手教你MacOS系统下Python的安装和配置
- 如何在Rstudio中使用Python?
- 基于Prometheus的监控告警系统的Python开发
- 用Python机器学习模型预测世界杯结果靠谱吗?附代码数据集
- 挑战30天学完Python:Day1火力全开-初识Python(含系列大纲)
- python自动化之BeautifulReport显示异常的解决方案
- Python遍历列表remove漏删解决方案
- python之pyinstaller打包问题系列(二)
- python之对比两张图像的相似度
- python之筛选图像中是否存在黑白背景
- 利用Python实现视频号自动赚钱一条龙
- 用 Python 写 3D 游戏,太赞了
- 成都核酸系统崩了,东软被市民连夜骂上了热榜第一,我用Python爬取了评论区,发现...
- Python实现实验室药品管理和预警系统(毕设源码)
- Python实现疫情医疗信息管理系统(附源码)
- 用Python写了一个合同帐务系统(附源码)