python速成 ---- if语句

 /  if -else结构

colors = ['red','gree','blue','orange']
for color in colors:
    if color == 'blue':
        print(color.upper())
    else :
        print(color)

 / if - elif - else 语句  (else 可省略)

age = int(input())    #输入年龄
if age <= 35:
    print("ten")
elif 35< age <=65:
    print("midlife")
else:
    print("senior")

  / 检查多个条件

age_0 = 32
age_1 = 18
if age_0 >=21 and age_1>=21:    #and ---两个条件都满足为Ture时运行
    print("All >=21")
if age_0 >=21 or age_1>=21:     #or ---只要满足一个条件都为Ture时运行
    print("At least one >=21")

 / 检查特定的值是否在列表中

colors = ['red','gree','blue','orange']
if "pink" in colors:         #判断 pink 是否在colors列表
    print("pink is my favorite")
if 'pink' not in colors:     #判断 pink 是否不在colors列表
    print("No one is my favorite")

  /  布尔表达式

colors = ['red','gree','blue','orange']
print("pink" in colors)
print('pink' not in colors)

布尔值(bool),是python内置数据类型的一种,属于整型(int)的子类,True和False都是有对应的数值,True=1,False=0.

print(True+True)
print(False+4)

  • 9
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值