/ 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)