目录
3.检查特定值是否在列表中in;not in,元素 in (not in) list,返回True or Flase
4.#if – else – else(多个else,多个选择):仅适用于一个条件满足。互斥的情况
1.判断语句
#==:相等返回True,否则False。 !=:不相等返回True,否则False。
a=5
b=6
if a==b:#相等为True
c=1
else:
c=0
print(c)
if a!=b:#不等为True
c=1
else:
c=0
print(c)
out:
0
1
2.两个if的情况
age_1=22
age_2=20
if age_1>18 and age_2>18:#and需两个条件同时满足,返回True
print('ok')
if age_1>20 or age_2>20:#or只需满足一个条件,则返回True
print('ok')
out:ok
ok
3.检查特定值是否在列表中in;not in,元素 in (not in) list,返回True or Flase
#检查特定值是否在列表中in;not in,元素 in (not in) list,返回True or Flase
list = ['zhao,','qian','sun']
'zhao' in list
print('zhao in the list')
'sun' not in list
print('sun not in the list')
out:zhao in the list
sun not in the list
4.#if – else – else(多个else,多个选择):仅适用于一个条件满足。互斥的情况
#if – else – else(多个else,多个选择):仅适用于一个条件满足。互斥
age = 30
if age <18:
print('1')
if 18<age<60:
print('2')
else :
print('3')
out:
2
5.#for 循环遍历与if条件语句结合使用:
available_toppings = ['a','b','c','d','e','f']
requested_toppings = ['a','c','e']
for requested_topping in requested_toppings:
if requested_topping in available_toppings:
print('ok')