Python if 语句
Python 3 教程
· 2019-02-12 10:13:54
以下实例通过使用 if...elif...else 语句判断数字是正数、负数或零:
实例(Python 3.0+)
# Filename : test.py
# author by : www.codercto.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.codercto.com
# 内嵌 if 语句
num = float(input("输入一个数字: "))
if num >= 0:
if num == 0:
print("零")
else:
print("正数")
else:
print("负数")
执行以上代码输出结果为:
输入一个数字: 0 零
点击查看所有 Python 3 教程 文章: https://www.codercto.com/courses/l/10.html
PHP实战
Dagfinn Reiersol、Marcus Baker、Chris Shiflett / 张颖 等、段大为 审校 / 人民邮电出版社 / 2010-01 / 69.00元
“对于那些想要在PHP方面更进一步的开发者而言,此书必不可少。” ——Gabriel Malkas, Developpez.com “简而言之,这是我所读过的关于面向对象编程和PHP最好的图书。……强烈推荐此书,绝不要错过!” ——Amazon评论 “此书是理论与实践的完美融合,到目前为止,其他任何图书都无法与它相媲美。如果5颗星是满分,它完全值得10颗星!” ——A......一起来看看 《PHP实战》 这本书的介绍吧!