跳到主要内容

5.if语句

条件测试

  • ==相等运算符
  • !=不相等
  • < >= <= >
  • and or多个条件
  • in not in检查特定值在列表中
animals = ['cat', 'dog', 'pig']
name = 'cats'
if name not in animals:
print(name)
  • 布尔表达式
active = True
inactive = False

if语句

  • if-else结构
  • if-elif-else结构