06.Python基础学习#条件控制

06.Python基础学习#条件控制

条件语句是通过一条或多条语句的执行结果(True 或者 False)来决定执行的代码块

返回布尔值 True False, 比较(关系)运算符 == 等等于(比较对象是否相等) != 不等于 > 大于 < 小于 >= 大于等于 <= 小于等于, 逻辑运算符 and 与(并且) or 或(或者) not 非(取反),成员运算符 in not in,身份运算符 is is not

if elif else

"""
条件语句是通过一条或多条语句的执行结果(`True` 或者 `False`)来决定执行的代码块
返回布尔值 `True False`, 比较(关系)运算符 `==` 等等于(比较对象是否相等) `!=` 不等于  `>` 大于 `<` 小于 `>=` 大于等于 `<=` 小于等于, 逻辑运算符 `and` 与(并且) `or` 或(或者) `not` 非(取反),成员运算符 `in` `not in`,身份运算符 `is` `is not` 等
"""
# python 判断语句 True False
t0 = 1
f0 = 0
t1 = True
f1 = False
result1 = 10 > 5
result2 = 10 >= 5
result3 = 5 > 10
result4 = 5 >= 10
print(result1, result2, result3, result4)
print("11" == "22")
print(11 == 22)
print(11 == 11)
print("22" == "22")
print("11" == 11)
print(22 == "22")

if f0:
    print(f0)
else:
    print(t0)
#

if result1:
    print(1)
else:
    print(2)
#

if result2:
    print(3)
elif result3:
    print(4)
else:
    print(5)
#

if not result4:
    print(6)
#

if type(1) == int:
    print(1)
else:
    print(0)
#

if type("1") == str:
    print(1)
else:
    print(0)
#

if 1 == 1:
    print(1)
    if 2 != 2:
        print(2)
    else:
        print(3)
else:
    print(4)
#

py.png

人生苦短,我学Python,人生漫漫,Python是岸!

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值