码迷,mamicode.com
首页 > 编程语言 > 详细

Python的学习之旅———流程控制之if...else....

时间:2017-09-07 14:47:55      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:false   print   int   hello   if语句   ...   img   blog   年龄   

if...else....

                          技术分享

如上面的流程表示 if符合条件(条件是true)就执行条件代码,如果条件为false,则执行eles的代码.

当然 if....eles是可以嵌套的.

Age=int(input("请输入你年龄:"))
Sex=input(‘请输入你的性别:‘)
hello = "你好美女"
if Age < 30 and Sex=="女":
print(hello)
elif Age>=30 and Sex=="女":
print(‘你好阿姨‘)
else:
print(‘你好老哥‘)

Python中if语句的一般形式如下所示:

if c_1: s_b_1 elif c_2: s_b_2 else: s_b_3
  • 如果 "c_1" 为 True 将执行 "s_b_1" 块语句
  • 如果 "c_1" 为False,将判断 "c_2"
  • 如果"c_2" 为 True 将执行 "s_b_2" 块语句
  • 如果 "c_2" 为False,将执行"s_b_3"块语句

Python 中用 elif 代替了 else if,所以if语句的关键字为:if – elif – else

Python的学习之旅———流程控制之if...else....

标签:false   print   int   hello   if语句   ...   img   blog   年龄   

原文地址:http://www.cnblogs.com/surehunter/p/7487593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!