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)
#
—— 人生苦短,我学Python,人生漫漫,Python是岸!